Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TooLongString
- {
- public static void main(String[] args)
- {
- String myString = "Codix be ready for my sunshine!";
- String parts[] = myString.split(" ");
- int getIforSwitch = 0;
- for (int i = 0; i < parts.length + 1; i++) { // parts.length + 1 because .length starts from 0;
- getIforSwitch = i;
- }
- switch (getIforSwitch) {
- case 1:
- System.out.println("This string contains one word!");
- break;
- case 2:
- System.out.println("This string contains two words!");
- break;
- case 3:
- System.out.println("This string contains three words!");
- break;
- case 4:
- System.out.println("This string contains four words!");
- break;
- case 5:
- System.out.println("This string contains five words!");
- break;
- case 6:
- System.out.println("This string contains six words!");
- break;
- case 7:
- System.out.println("This string contains seven words!");
- break;
- case 8:
- System.out.println("This string contains eight words!");
- break;
- case 9:
- System.out.println("This string contains nine words!");
- break;
- case 10:
- System.out.println("This string contains ten words!");
- break;
- default:
- System.out.println("This string contains more than ten words!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement