gpt4 book ai didi

java - 一般输出不返回任何内容

转载 作者:行者123 更新时间:2023-12-01 04:11:01 25 4
gpt4 key购买 nike

我正在尝试使用 Stringtokenizer 读取文件中的几行并使用 while 循环显示相关信息(对于学校项目),但 JCreator 中的一般输出似乎没有返回尽管我做了任何改变。

import java.io.*;
import java.util.StringTokenizer;

public class EmployeePayWeek10

{
//file input variables
private static FileInputStream inFile;
private static InputStreamReader inReader;
private static BufferedReader reader;

//StringTokenizer variable
private static StringTokenizer stringTkn;

//Data variables
private static String firstName, lastName, line;
private static double hourlyWage;
private static double hoursMon, hoursTue, hoursWed, hoursThu, hoursFri;
private static double ovtMon, ovtTue, ovtWed, ovtThu, ovtFri;
private static double ovtHoursWorked, hoursWorked, effectiveWage, roundedWage;
private static double weeklyWage;

public static void main(String args[]) throws IOException

{

startFile();
acquireValues();
inFile.close();


}
//Initializing the file
public static void startFile() throws IOException

{

inFile = new FileInputStream ("C:\\!!VHSJava\\!!VHSAPCSData\\VHSP35week10data.txt");
inReader = new InputStreamReader(inFile);
reader = new BufferedReader(inReader);

}
//Acquiring data values from the .txt file
public static void acquireValues() throws IOException

{

line = reader.readLine();

while(line != null);
{

//Separating the series of words into tokens
stringTkn = new StringTokenizer(line);

//Name variables
firstName = stringTkn.nextToken();
lastName = stringTkn.nextToken();

//Wage variables, defined in order of the notepad file
hourlyWage = Double.parseDouble(stringTkn.nextToken());
hoursMon = Double.parseDouble(stringTkn.nextToken());
ovtMon = Double.parseDouble(stringTkn.nextToken());
hoursTue = Double.parseDouble(stringTkn.nextToken());
ovtTue = Double.parseDouble(stringTkn.nextToken());
hoursWed = Double.parseDouble(stringTkn.nextToken());
ovtWed = Double.parseDouble(stringTkn.nextToken());
hoursThu = Double.parseDouble(stringTkn.nextToken());
ovtThu = Double.parseDouble(stringTkn.nextToken());
hoursFri = Double.parseDouble(stringTkn.nextToken());
ovtFri = Double.parseDouble(stringTkn.nextToken());

calcWage();
returnWage();


line = reader.readLine();

}
}

//Weekly wage is calculated and rounded to two decimal places. (At most)

public static void calcWage() throws IOException
{

hoursWorked = (hoursMon + hoursTue + hoursWed + hoursThu + hoursFri);
ovtHoursWorked = (ovtMon + ovtTue + ovtWed + ovtThu + ovtFri);
effectiveWage = (hoursWorked * hourlyWage) + (1.5 * ovtHoursWorked * hourlyWage);
roundedWage = (double)Math.round(effectiveWage * 100) / (100);

}

//Calculated weekly wage is returned alongside name of employee.

public static void returnWage() throws IOException
{
System.out.println(firstName + lastName + "Weekly Wage: " + roundedWage);
}
} //End of class

我尝试过其他程序来查看输出是否由于 Java 问题而困惑,但其他文件工作正常。这里有什么可能会干扰显示的输出吗?

最佳答案

错误出现在 acquireValues() 方法中:

while(line != null);

你有一个;,它不应该在那里。删除它。

关于java - 一般输出不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19921908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com