fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int arr[][] = new int[3][3];
  13. int nullength = 2;
  14. int nulweight = 2;
  15. int nextlenght = 0;
  16. int nextweight = 0;
  17. Scanner s = new Scanner(System.in);
  18. String move = s.nextLine();
  19. move.split(" ");
  20.  
  21. System.out.println(moveRobot(nextlenght, nextweight, move));
  22. }
  23.  
  24. public static boolean moveRobot(int nextlenght, int nextweight, String move) {
  25. for (int i = 0; i < move.length(); i++) {
  26.  
  27. if (Character.toString(move.charAt(i)).equals("U")) {
  28. nextweight = nextweight + 1;
  29. }
  30. if (Character.toString(move.charAt(i)).equals("D")) {
  31. nextweight = nextweight - 1;
  32. }
  33. if (Character.toString(move.charAt(i)).equals("L")) {
  34. nextlenght = nextlenght - 1;
  35. }
  36. if (Character.toString(move.charAt(i)).equals("R")) {
  37. nextlenght = nextlenght + 1;
  38. }
  39.  
  40. }
  41.  
  42. if (nextlenght == 0 && nextweight == 0) {
  43. return true;
  44. } else {
  45. return false;
  46. }
  47.  
  48. }
  49. }
Success #stdin #stdout 0.06s 2184192KB
stdin
UUDLDR
stdout
true