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)
  11. {
  12.  
  13. System.out.println(isExactReverse("ba", "a"));
  14. System.out.println(isExactReverse("desserts", "stressed"));
  15. System.out.println(isExactReverse("apple", "apple"));
  16. System.out.println(isExactReverse("regal", "lager"));
  17. System.out.println(isExactReverse("war", "raw"));
  18. System.out.println(isExactReverse("pal", "slap"));
  19.  
  20.  
  21. }
  22. public static boolean isExactReverse(String x, String y)
  23. {
  24. if (x.length() != y.length()) return false;
  25. //To be completed
  26. int counter = 0;
  27. int temp = x.length() - 1;
  28. boolean result = false;
  29.  
  30. for(int i = 0; i < y.length(); i++)
  31. {
  32. if(x.charAt(temp) == y.charAt(i))
  33. {
  34. counter++;
  35. }
  36. temp--;
  37. }
  38. if(counter == y.length())
  39. {
  40. result = true;
  41. }
  42.  
  43. return result;
  44. }
  45. }
Success #stdin #stdout 0.05s 27820KB
stdin
Standard input is empty
stdout
false
true
false
true
true
false