我正在尝试为我的布尔方法的参数中的输出文件使用PrintWriter。eclipse中的错误告诉我PrintWriter无法解析为变量。错误发生在if(!validgroup)...我是一个非常新手的编码人员,不久前就开始了。任何帮助或建议,将不胜感激。
import java.io.*;
import java.util.*;
public class BowlingScores {
public static void main(String args[]) throws IOException{
File myFile = new File("scoresInput.txt"); // Making a new .txt file for input
Scanner inputFile = new Scanner(myFile); // Letting it read the file
PrintWriter outputFile = new PrintWriter("scoresOutput.txt"); // Creating the .txt output file
int score1, score2, score3, totalGroups = 1;
score1 = inputFile.nextInt();
while(score1 != -999) {
score2 = inputFile.nextInt();
score3 = inputFile.nextInt();
outputFile.print("Score 1: " + score1 + " ");
outputFile.print("Score 2: " + score2 + " ");
outputFile.print("Score 3: " + score3 + " \n\n\n");
score1 = inputFile.nextInt();
outputFile.println("Total number of groups processed: " + totalGroups);
totalGroups++;
if(!validGroup(score1, score2, score3, PrintWriter)) {
outputFile.println("Group is invalid");
}
}
inputFile.close();
outputFile.close();
}
public static boolean validGroup(int score1, int score2, int score3, PrintWriter scoresOutput) {
boolean validGroup = true;
if(score1 > 300 && score1 < 0) {
validGroup = false;
}
if(score2 > 300 && score2 < 0) {
validGroup = false;
}
if(score3 > 300 && score3 < 0) {
validGroup = false;
}
return validGroup;
}
}
更改
if(!validGroup(score1, score2, score3, PrintWriter)) {
至
if(!validGroup(score1, score2, score3, outputFile)) {
另外,你是不是实际使用scoresOutput
中validGroup
-所以目前尚不清楚为什么你添加它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句