-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordCounter.java
More file actions
65 lines (34 loc) · 1.48 KB
/
WordCounter.java
File metadata and controls
65 lines (34 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package sessao10;
import java.util.Scanner;
public class WordCounter {
public static void main(String[] args) {
//このプログラムは入力された文章の文字を数えます
//このぷろがむはにゅうろくされたぶんしょのもじすをかぞえます。
// This program counts the number of letters on the phrase.
//Este programa conta o número de palavras da frase inserida.
callStart();
continueCall();
}
public static void callStart(){
Scanner scanner = new Scanner(System.in);
System.out.println("Insert any phrase here. It will be counted.");
String phraseInserted = scanner.nextLine();
int amountLetters = phraseInserted.length();
System.out.println("The phrase ''" +phraseInserted+"'' has the amount of " +amountLetters+ " letters.");
continueCall();
}
public static void continueCall(){
Scanner scanner = new Scanner(System.in);
System.out.println("Do you want print another phrase? (1) Yes, (2) No.");
int printAgain = scanner.nextInt();
if (printAgain == 1){
callStart();
} else if (printAgain == 2){
System.out.println("Program ended.");
System.exit(0);
} else {
System.out.println("Invalid input. Try again.");
continueCall();
}
}
}