Advertisement
irmantas_radavicius

Untitled

Mar 2nd, 2022
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. public class Sandbox {
  5.  
  6.     public static void main(String args[]) {       
  7.         try {      
  8.             Scanner sc = new Scanner(System.in);
  9.             System.out.print("Please enter a line: ");
  10.             String str = sc.nextLine();
  11.            
  12.             boolean hasLetters = true;
  13.             int firstWordLength = str.length();
  14.             for(int i = 0; i < str.length(); ++i){
  15.                 if (!Character.isLetter(str.charAt(i))){
  16.                     firstWordLength = i;
  17.                     break;
  18.                 }
  19.             }
  20.  
  21.             System.out.print("Length is " + firstWordLength + ", ");
  22.             System.out.println(((firstWordLength <= 6) ? "short" : "long") + " first word");
  23.            
  24.            
  25.             sc.close();        
  26.  
  27.         } catch(Exception e){
  28.             System.out.println(e);
  29.             System.out.println("Unexpected error, sorry!");
  30.         }      
  31.        
  32.     }
  33.    
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement