Computers and Technology

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

}

}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 15:30, ninja12302
Some of the items below indicate the steps required to move a slide to a different location in a presentation. select those steps and indicate the order in which they should be performed to move the slide. (for example, if an item describes what you do first, select 1.) included in the list are items that are not part of the process. for these items, select n/a, an abbreviation for not applicable. 1 — first 2 — second 3 — third 4 — fourth 5 — fifth 6 — sixth n/a — not applicable drag the slide to the desired place. enter the slide position desired. hold the mouse button down. select move from the tools menu. select the slide. switch to the notes view.
Answers: 3
image
Computers and Technology, 22.06.2019 11:40, malibu777
Design a pos circuit that displays the letters a through j on a seven-segment indicator. the circuit has four inputs w, x, y, and z which represent the last 4 bits of the uppercase ascii code for the letter to be displayed. thus, if wxyz = 0001 then "a" will be displayed. (any answer with 22 or fewer gates and inverters, not counting any for the inputs, is acceptable)
Answers: 2
image
Computers and Technology, 23.06.2019 17:00, Alexaisokay1
In which of the following ways can using test-taking tips you? a. you can focus on the information that you need to study. b. you will see the answers to the test. c. you will study more. d. you will be less organized.
Answers: 1
image
Computers and Technology, 23.06.2019 20:00, emmaraeschool
Me ajude por favor , coloquei uma senha e não consigo tira-la no chorme
Answers: 2
Do you know the correct answer?
We want to create a "Greeting Counter" that tell us how many times you entered a greeting. Improve t...

Questions in other subjects:

Konu
Health, 07.06.2021 16:10