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 14:00
How are stop motion special effects in animated films created
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Which of the following would not be considered a pc? a. mainframe b. desktop c. tablet pc d. laptop
Answers: 2
question
Computers and Technology, 23.06.2019 15:00
To check whether your writing is clear , you can
Answers: 2
question
Computers and Technology, 23.06.2019 20:40
Instruction active describing list features which statements accurately describe the features of word that are used to create lists? check all that apply. the tab key can be used to create a sublist. the enter key can be used to add an item to a list. the numbering feature allows for the use of letters in a list. the numbering feature can change the numbers to bullets in a list. the multilevel list feature provides options for different levels in a list.
Answers: 2
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
question
Mathematics, 27.04.2021 17:30
question
Mathematics, 27.04.2021 17:30
question
Social Studies, 27.04.2021 17:30
Questions on the website: 13722363