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. //write a function that takes two words as parameter and return true if
  8. //they are reversed or false otherwise.
  9. //"Ahoj", "johA" => true
  10. //"Liska", "iska" => false
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17. System.out.println(reversed("Ahoj", "jhA"));
  18. }
  19.  
  20. public static boolean reversed(String parFirst, String parSecond)
  21. {
  22. if(parFirst.length()!=parSecond.length())
  23. {
  24. return false;
  25. }
  26. int secondSize = parSecond.length()-1;
  27. for(int i = 0; i<parFirst.length();i++)
  28. {
  29.  
  30. if(parFirst.charAt(i) != parSecond.charAt(secondSize))
  31. {
  32. return false;
  33. }
  34. secondSize--;
  35. }
  36. return true;
  37. }
  38. }
Success #stdin #stdout 0.1s 46764KB
stdin
Standard input is empty
stdout
false