wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes where is wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "where is wrong?" Watch "where is wrong?" New topic
Author

where is wrong?

weiliu lili
Ranch Hand

Joined: Apr 11, 2002
Posts: 46
1. public class TeSet {
2. public static void main(String args[]) {
3. int m = 2;
4. int p = 1;
5. int t = 0;
6. for(;p < 5;p++) {
7. if(t++ > m) {
8. m = p + t;
9. }
10. }
11. System.out.println("t equals " + t);
12. }
13. }
TeSet.java:1: 'class' or 'interface' expected
1. public class TeSet {
^
TeSet.java:2: illegal start of type
2. public static void main(String args[]) {
^
TeSet.java:13: <identifier> expected
13. }
^
3 errors
where is the bug?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You need to remove the line numbers.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
The exact same code with the line numbers removed compiles just fine.
Note that I've also formatted the layout of the example code and surrounded the code with the [ code ] and [ /code ] ubb tags in order to preserve the formatting.
Good Luck.
Steven Sun
Greenhorn

Joined: Apr 29, 2002
Posts: 26
Originally posted by weiliu lili:
1. public class TeSet {
2. public static void main(String args[]) {
3. int m = 2;
4. int p = 1;
5. int t = 0;
6. for(;p < 5;p++) {
7. if(t++ > m) {
8. m = p + t;
9. }
10. }
11. System.out.println("t equals " + t);
12. }
13. }
TeSet.java:1: 'class' or 'interface' expected
1. public class TeSet {
^
TeSet.java:2: illegal start of type
2. public static void main(String args[]) {
^
TeSet.java:13: <identifier> expected
13. }
^
3 errors
where is the bug?

呵呵,好玩


newly SCJP2 <img src="tongue.gif" border="0">
Asif Mahmood
Greenhorn

Joined: Jun 11, 2001
Posts: 29
Weiliu, there is nothing wrong with the code. All that you need to do is to remove the line numbers. Remove the line numbers, and then compile. Line numbers are give just for the reference. They are not part of the actual code.
Best regards
-Asif
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where is wrong?
 
Similar Threads
for loop doubt
Help, 2 hours before exam
may be this is very basic question...........
Sun ePractice question 5 loop/post-increment
q from sun's epractice exams