正在完成这项任务 这是我的代码:
public void part2() {
while (check) {
try {
System.out.println("Enter Payroll Period:\tSample: JAN-21-2016");
payperiod = input.nextLine();
period = payDate.parse(payperiod);
payperiod = period.toString();
Scanner error = new Scanner(System.in);
String temp = "";
int count = 0;
char[] chtrs;
Path file = Paths.get("Employee.txt");
File location = new File(file.toString());
FileReader employeeFile = new FileReader(location);
BufferedReader lineReader = new BufferedReader(employeeFile);
List<String> except = new ArrayList<>(), holdLast = new ArrayList<>();
while ((temp = lineReader.readLine()) != null) {
int cont = 0;
for (char ime : temp.toCharArray()) {
char[] characters = new char[temp.toCharArray().length];
characters[cont] = temp.charAt(cont);
cont++;
}
except.add(temp);
count++;
}
for (int i = 0; i < except.toArray().length && i == except.toArray().length; i++) {
System.out.print("Enter number of days worked for " + except.toArray()[i] + ":\t");
int numDays = input.nextInt();
String thump = except.toArray()[i].toString() + " " + numDays;
System.out.println(thump + " <- dude its in");
holdLast.add(thump);
System.out.println(except + " <- check errors except\n holdLast -> " + holdLast);
check = false;
}
} catch (FileNotFoundException e) {
System.err.println("NO RECORD EXISTS!");
System.out.println("Create a new one first by choosing 1");
MidActExam4 token = new MidActExam4();
token.start();
} catch (IOException e) {
System.err.println(e.getMessage());
} catch (Exception e) {
System.err.println(e.getMessage() + e.getCause() + e.getStackTrace());
}
}
}
输出:
XYZ Company
1 Employee Masterdata
2 Payroll Transactions
3 Compute Payroll
4 Exit
Select an option: F
Invalid Input!
XYZ Company
1 Employee Masterdata
2 Payroll Transactions
3 Compute Payroll
4 Exit
Select an option: 2
Enter Payroll Period: Sample: JAN-21-2016
Jan-1-2014 //first input
Enter Payroll Period: Sample: JAN-21-2016
jan-8-2013 //my input the second time
Enter Payroll Period: Sample: JAN-21-2016 //this line keeps on running
答案 0 :(得分:1)
你永远不会进入内循环(因此永远不会退出主循环):
for (int i = 0; i < except.toArray().length && i == except.toArray().length; i++) {
...
check = false;
}
因为永远不会达到条件i < except.toArray().length && i == except.toArray().length;
。
整数如何小于某个值,同时又等于该值......?
您可能将i < except.toArray().length
视为for
条件。