java - 如何在布尔方法中使用 PrintWriter 作为参数
问题描述
我正在尝试在我的布尔方法的参数中使用 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
in validGroup
- 所以不清楚为什么添加它。
推荐阅读
- three.js - 如何使用 html 范围滑块修改 three.js 中的 animate() 速度?
- java - 向 LocalTime 添加持续时间
- jquery - 如果我们在单击时禁用了按钮,工具提示不会隐藏
- jenkins - 仅在必要时构建 jenkins 管道子作业
- react-native - Refetch Query on Navigating to screen 再次 React Native
- python - 使用 Selenium Python 下载嵌入式 SVG?
- python - 过滤具有最后修改时间的文件
- shell - 我输入了一个 shellscript 程序来生成一个数字表。我正在使用onworks(在线操作系统平台)
- android - Android 中的 Firebase 通知 (Kotlin)
- centos - 构建 HPL 的问题