subject

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

So my answer keeps getting infinite loop errors and I'm not sure where I'm going wrong.

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);

}

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 00:30
Which of the following would you find on a network
Answers: 3
question
Computers and Technology, 23.06.2019 16:30
If i wanted to include a built-in calendar in a document, what option could i select? draw table insert table insert chart quick tables
Answers: 1
question
Computers and Technology, 23.06.2019 22:50
An environmental protection agency study of 12 automobiles revealed a correlation of 0.47 between engine size and emissions. at 0.01 significance level, can we conclude that there is a positive association between the variables? what is the p value? interpret.
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
Answer these and get 40 points and brainliest
Answers: 1
You know the right answer?
We want to create a "Greeting Counter" that tell us how many times you entered a greeting. Improve t...
Questions
Questions on the website: 13722367