Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LongPhrase {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter text");
- String phrase = scanner.nextLine();
- phrase.trim();
- String[] result = phrase.split(" ");
- switch (result.length){
- case 0:
- System.out.println("no words");
- break;
- case 1:
- //checking result[0] for content
- if(result[0].equals("")){
- System.out.println("no words.");
- }
- else {
- System.out.println("One word");
- }
- break;
- case 2:
- System.out.println("Two words");
- break;
- case 3:
- System.out.println("Three words");
- break;
- case 4:
- System.out.println("Four words");
- break;
- case 5:
- System.out.println("Five words");
- break;
- case 6:
- System.out.println("Six words");
- break;
- case 7:
- System.out.println("Seven words");
- break;
- case 8:
- System.out.println("Eight words");
- break;
- case 9:
- System.out.println("Nine words");
- break;
- default:
- System.out.println("Very long phrase");
- }
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement