Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class WordsCounter {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. System.out.println("Write a sentence here: ");
  7. String sentence = scan.nextLine();
  8.  
  9. String [] words = sentence.split(" ");
  10. int countWords = words.length;
  11.  
  12. switch (countWords) {
  13. case 1 :
  14. System.out.println("one");
  15. break;
  16. case 2 :
  17. System.out.println("two");
  18. break;
  19. case 3 :
  20. System.out.println("three");
  21. break;
  22. case 4 :
  23. System.out.println("four");
  24. break;
  25. case 5 :
  26. System.out.println("five");
  27. break;
  28. case 6 :
  29. System.out.println("six");
  30. break;
  31. case 7 :
  32. System.out.println("seven");
  33. break;
  34. case 8 :
  35. System.out.println("eight");
  36. break;
  37. case 9 :
  38. System.out.println("nine");
  39. break;
  40. case 10 :
  41. System.out.println("ten");
  42. break;
  43. default:
  44. System.out.println("The sentence is too long");
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement