Advertisement
jwrbg

CheckWordsInSentence

Feb 14th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package com;
  2.  
  3.     import java.util.Scanner;
  4.  
  5. public class CheckWordsInSentence
  6. {
  7.   public static void main(String[] args)
  8.   {
  9.     Scanner scanner = new Scanner(System.in);
  10.  
  11.     String sentence = scanner.nextLine();
  12.  
  13.     int lengthOfSentence = sentence.split("\\s+").length;
  14.  
  15.     switch (lengthOfSentence){
  16.       case 0:
  17.         System.out.println("Zero");
  18.         break;
  19.       case 1:
  20.         System.out.println("One");
  21.         break;
  22.       case 2:
  23.         System.out.println("Two");
  24.         break;
  25.       case 3:
  26.         System.out.println("Three");
  27.         break;
  28.       case 4:
  29.         System.out.println("Four");
  30.         break;
  31.       case 5:
  32.         System.out.println("Five");
  33.         break;
  34.       case 6:
  35.         System.out.println("Six");
  36.         break;
  37.       case 7:
  38.         System.out.println("Seven");
  39.         break;
  40.       case 8:
  41.         System.out.println("Eight");
  42.         break;
  43.       case 9:
  44.         System.out.println("Nine");
  45.         break;
  46.       case 10:
  47.         System.out.println("Ten");
  48.         break;
  49.       default:
  50.         System.out.println("Sentence is too big")
  51.         ;break;
  52.     }
  53.  
  54.  
  55.  
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement