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 09:00
Which is the highest level of the hierarchy of needs model? a. humanity b. intrapersonal c. team d. interpersonal
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
Companies that implement and apply an information system effectively can create
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Amitha writes up a one-page summary of a novel during her summer internship at a publishing company. when she reads over the page, she realizes she used the word “foreshadow” seven times, and she would like to reduce the repetition. which tool would best amitha solve this problem?
Answers: 3
question
Computers and Technology, 24.06.2019 00:50
3. what is the output of the following statements? temporary object1; temporary object2("rectangle", 8.5, 5); temporary object3("circle", 6, 0); temporary object4("cylinder", 6, 3.5); cout < < fixed < < showpoint < < setprecision(2); object1.print(); object2.print(); object3.print(); object4.print(); object1.set("sphere", 4.5, 0); object1.print();
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
question
Mathematics, 16.12.2020 21:50
question
Mathematics, 16.12.2020 21:50
question
Mathematics, 16.12.2020 21:50
question
Health, 16.12.2020 21:50
question
Mathematics, 16.12.2020 21:50