Advertisement
Dilyana86

Untitled

Apr 11th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class aniIsDrunk160815 {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. int cabins = Integer.parseInt(scan.nextLine());
  7. String command = scan.nextLine();
  8. int currentPos = 0;
  9. int count = 0;
  10.  
  11. while(!(command.equals("Found a free one!"))){
  12. int steps = Integer.parseInt(command);
  13. int oldPos = currentPos;
  14. currentPos = (currentPos + steps) % cabins;
  15. int diff = currentPos - oldPos;
  16. count = count + Math.abs(diff);
  17. if(diff > 0){
  18. System.out.printf("Go %d steps to the right, Ani%n",diff);
  19. }else if(diff <0){
  20. System.out.printf("Go %d steps to the left, Ani%n", Math.abs(diff));
  21. }else{
  22. break;
  23. }
  24. command = scan.nextLine();
  25. }
  26. System.out.printf("Moved a total of %d steps.",count);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement