Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Sandbox {
- public static void main(String args[]) {
- try {
- Scanner sc = new Scanner(System.in);
- System.out.print("Please enter a line: ");
- String str = sc.nextLine();
- boolean hasLetters = true;
- int firstWordLength = str.length();
- for(int i = 0; i < str.length(); ++i){
- if (!Character.isLetter(str.charAt(i))){
- firstWordLength = i;
- break;
- }
- }
- System.out.print("Length is " + firstWordLength + ", ");
- System.out.println(((firstWordLength <= 6) ? "short" : "long") + " first word");
- sc.close();
- } catch(Exception e){
- System.out.println(e);
- System.out.println("Unexpected error, sorry!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement