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. if(canSpell("cenimatography","minato")) {
  13. System.out.println("it CAN spell");
  14. } else {
  15. System.out.println("it CANNOT spell");
  16. }
  17.  
  18. // Or make a separate method, ya'know.
  19. if(canSpell("cenimatgraphy","minato")) {
  20. System.out.println("it CAN spell");
  21. } else {
  22. System.out.println("it CANNOT spell");
  23. }
  24. }
  25.  
  26. public static boolean canSpell(String letter, String word) {
  27. for(int i=0;i<word.length();i++) {
  28. if(letter.indexOf(word.charAt(i)) == -1) { // <-- change to '=='
  29. return false;
  30. } else {
  31. int charLocation = letter.indexOf(word.charAt(i));
  32. letter = letter.substring(0,charLocation)
  33. + letter.substring(charLocation+1,letter.length());
  34. }
  35. }
  36.  
  37. return true;
  38. }
  39. }
  40.  
  41.  
Success #stdin #stdout 0.04s 320576KB
stdin
Standard input is empty
stdout
it CAN spell
it CANNOT spell