함수에서 일부 사용자 입력을 얻으려고하고 있지만 어떤 이유로 내 코드가 입력 스트림을 인식하지 못합니다. 컴파일 할 때 81 행에 reader.readLine()을 찾을 수 없다는 오류가 발생합니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까? 아니면 실행 기능이 문제없이 초기 DO-while 루프에서 일어나는 것이 가능하다?의기능에서 기호를 찾을 수 없습니다.
import java.io.*;
public class JavaLab3 {
public static void main(String[] args) {
// first we define our input streams.
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
// variable declarations
String sName, playAgain;
// we catch exceptions if some are thrown.
// an exception would be entering a string when a number is expected
try {
System.out.println("what is your name?");
// we read a string from the stream
sName = reader.readLine();
do {
run();
System.out.println(sName + "would you like to play again?");
System.out.println("Please answer in lowercase 'yes' or 'no'.");
playAgain = reader.readLine();
} while (playAgain != "no");
} catch (IOException e){
System.out.println("Error reading from user");
}
}
public static int maxRun (int runTotal) {
int highScore = 0;
if (runTotal > highScore) {
highScore = runTotal;
} else {
`highScore = highScore`}
return highScore;
}
public static int run() {
Integer currentRun = 0, uNumber, counter;
final Integer MAX = 4;
final Integer MAX_NUMBER = 100;
//While current total is less than the max
while (currentRun < MAX) {
System.out.println("Please enter a number.");
//store user number
uNumber = Integer.parseInt(reader.readLine()); //Line throwing the error.
//for each number under 5 repetitions
for (counter = 0; counter <= MAX_NUMBER ; counter++) {
if (uNumber < 0) {
System.out.println("Please enter a positive number.");
} else if ((uNumber % 2) != 0) {
System.out.println("Please enter an even number.");
} else {
//sets current total and restarts the loop
currentRun = uNumber + currentRun;
}
}
}
//Calls maxRun function to see if score the score is the highest.
maxRun(currentRun);
System.out.println("The max for this run was, " + currentRun + ".");
return currentRun;
}
}