Advertisement
476179

idk

Nov 15th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package act;
  2. import java.util.Scanner;
  3. public class act2Whileloop
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. Scanner keyboard = new Scanner(System.in);
  9. System.out.print("enter ur name:");
  10. String name = keyboard.nextLine();
  11. name = name.toLowerCase();
  12.  
  13. int last = name.length()-1;
  14. char firstL = name.charAt(0);
  15. char lastL = name.charAt(last);
  16.  
  17.  
  18. String f = Character.toString(firstL);
  19. String l = Character.toString(lastL);
  20.  
  21.  
  22. while (!(name.equals("done") ))
  23. {
  24. if(f.equals(l)){
  25. System.out.println("The first letter of the word matches the last letter of the word.");
  26. System.out.print("enter ur name:");
  27. name = keyboard.nextLine();
  28. name = name.toLowerCase();
  29.  
  30. last = name.length()-1;
  31. firstL = name.charAt(0);
  32. lastL = name.charAt(last);
  33.  
  34. f = Character.toString(firstL);
  35. l = Character.toString(lastL);
  36.  
  37. }
  38. else
  39. {
  40. System.out.println("The first letter of the word does not match the last letter of the word.");
  41. System.out.print("enter ur name:");
  42. name = keyboard.nextLine();
  43. name = name.toLowerCase();
  44.  
  45. last = name.length()-1;
  46. firstL = name.charAt(0);
  47. lastL = name.charAt(last);
  48.  
  49. f = Character.toString(firstL);
  50. l = Character.toString(lastL);
  51.  
  52.  
  53. }
  54. }
  55. System.out.println("The word \"done\" has been entered. Program has ended.");
  56.  
  57. keyboard.close();
  58.  
  59.  
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement