|
|||||||
| Java (NOT JavaScript!) For discussion of the Java programming language as it applies to the Web ( Not JavaScript ). |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
"illegal start of expression" help needed
I'm trying to write a Java program that will open a .txt file and read the contents of it to do payroll. I'm new to Java and haven't been too successful at this program attempt tonight and I need some help with an error I'm getting. The error states:
employeePayroll.java:29: ';' expected for (int i = 0; i+3) ^ employeePayroll.java:35: illegal start of expression } ^ 2 errors And my code is: Code:
//Imports the keyboard scanner
import java.util.Scanner;
//To use the classes that use a .txt file
import java.io.*;
public class employeePayroll
{
public static void main(String[] args) throws IOException
{
String filename; //file name
String name; //employee name
//Create a Scanner object to read input
Scanner keyboard = new Scanner (System.in);
// Open the file.
FileReader freader = new FileReader("data.txt");
BufferedReader inputFile = new BufferedReader(freader);
String str;
// Read the first item.
str = inputFile.readLine();
// If an item was read, display it and read the remaining items.
int i = 0;
for (int i = 0; i+3)
{
System.out.println(str);
str = inputFile.readLine();
}
inputFile.close();
}
}
//ALL DONE!
Thank you |
|
#2
|
||||
|
||||
|
As long as I know, for loops need to semicolons my friend, as they also need a condition to end the loop, you may use: (here the condition is i being smaller than max)
for (i=0;i<max;i+=3) {... or in case you don't know where to end, you should use a while loop: end_achieved=0; i=0; while(!end_echieved) { ... if(we_should_finish_this_loop) end_achieved=1; } |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|