import java.util.*;

public class course

{

static Scanner sc=new Scanner(System.in);

public static void main(String[]args)

{

String name,students,addStudent;

int numberOfStudents;

String courseName,getName,getStudents;

int getnumberOfStudents;

Course course1=new Course("C++");

Course course2=new Course("Java");

course1.addStudent("Peter");

course1.addStudent("Brian");

course1.addStudent("Anne");

course2.addStudent("Peter");

course1.addStudent("Steve");

System.out.println("Num of student in course1:"+course1.getnumberOfStudents());

String[]students=course1.getStudents();

for (int i = 0; i < course1.getNumberOfStudents(); i++)

System.out.println("Num of student in course2:"+course2.getnumberOfStudents());

String[]students=course2.getStudents();

for (int i = 0; i < course2.getNumberOfStudents(); i++)
}

}

C:\Documents and Settings\Administrator\Desktop\course\src\course.java:37: illegal start of expression
}
^
C:\Documents and Settings\Administrator\Desktop\course\src\course.java:38: reached end of file while parsing
}2 errors

Process completed.
this is the error and i cant understand. the errors is in the last 2 lines which are the last 2 brackets.....
already change the getNumberOfStudents to getnum....
but same error generated


actually the Question is like this:
create 2 courses which are c++ n java
then, add students to c++ n java
print out the num of students taking c++ and the list of their names
print out the num of students taking java and the list of their names

You cant end a program with an empty for loop. Either fill it with something or get rid of it. The compiler is expecting your for loop to have a body to it but it currently does not.

Edited 7 Years Ago by Grn Xtrm: n/a

You cant end a program with an empty for loop. Either fill it with something or get rid of it. The compiler is expecting your for loop to have a body to it but it currently does not.

can you please show me how to write the body...thanks. i am new in java

In your first for loop you should be printing the students in course 1. I'd change line 42 to

System.out.println("Num of student in course1:"+course1.getnumberOfStudents());

Then your second for loop would be the same only replacing 1's with 2's.

Also I am assuming that your methods are defined somewhere in a separate file. Am I right in assuming this?

This question has already been answered. Start a new discussion instead.