• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where is wrong?

 
weiliu lili
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to remove the line numbers.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

呵呵,好玩
 
Asif Mahmood
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic