Guest User

Untitled

a guest
May 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. {
  2. Scanner input = new Scanner(System.in);
  3. // Declare variables
  4. int length;
  5. char first, last;
  6. String line;
  7.  
  8. System.out.println("Enter a string: ");
  9. line = input.nextLine();
  10. length = line.length();
  11. if (length > 0);
  12. {
  13. first = line.charAt(0);
  14. last = line.charAt(length-1);
  15.  
  16. if ((Character.isLetter(first)) && (Character.isLetter(last)))
  17. System.out.println("\"" + line + "\" is a word.");
  18.  
  19. if ((Character.isDigit(first)) && (Character.isDigit(last)))
  20. System.out.println("\"" + line + "\" is a number.");
  21.  
  22. else
  23. System.out.println("\"" + line + "\" is something else.");
  24. }
  25.  
  26. else
  27. System.out.println("Empty String");
  28. }
  29. }
Add Comment
Please, Sign In to add comment