Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Scanner input = new Scanner(System.in);
- // Declare variables
- int length;
- char first, last;
- String line;
- System.out.println("Enter a string: ");
- line = input.nextLine();
- length = line.length();
- if (length > 0);
- {
- first = line.charAt(0);
- last = line.charAt(length-1);
- if ((Character.isLetter(first)) && (Character.isLetter(last)))
- System.out.println("\"" + line + "\" is a word.");
- if ((Character.isDigit(first)) && (Character.isDigit(last)))
- System.out.println("\"" + line + "\" is a number.");
- else
- System.out.println("\"" + line + "\" is something else.");
- }
- else
- System.out.println("Empty String");
- }
- }
Add Comment
Please, Sign In to add comment