Answer the question
In order to leave comments, you need to log in
Why is the program not working properly?
I wrote a simple program that should ask for 1 character until a period is entered. If a period is entered, the number of times Enter was pressed (i.e., the number of attempts to guess the character) is displayed. If the user enters "q", then the program exits.
class Point {
public static void main(String args[])
throws java.io.IOException {
char choice;
int count;
count = 0;
do {
System.out.print("Введите любой символ: ");
choice = (char) System.in.read();
System.out.println();
count++;
} while (choice != '.' | choice != 'q');
switch(choice) {
case '.':
System.out.println("Вы нажали Enter " + count + " раз.");
break;
case 'q':
break;
}
}
}
C:\Users\Alex\Desktop\Projects\Point>java Point
Введите любой символ: .
Введите любой символ:
Введите любой символ:
Введите любой символ: q
Введите любой символ:
Введите любой символ:
Введите любой символ:
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question