We want to create a "Greeting Counter" that tell us how many times you entered a greeting. Improve the program that takes any number of words in a single line as input, and outputs the number of greetings. Valid greetings to count are "Hi", "Hello" and "Hey". Different cases are allowed. The input ends with -1 on a line alone.
Ex: If the input is:
Hi World Hey -1
then the output is:
Greetings: 2
import java.util.Scanner;
public class GreetCounter {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String input = scnr.nextLine();
int i = 1;
while(!input.equals("-1")) {
if (input.equals("Hi") || input.equals("Hello") || input.equals("Hey")) {
i +=0;
}
}
System.out.print("Greetings: ");
System.out.println(i);
}
}