• Post Reply Bookmark Topic Watch Topic
  • New Topic

simple question about my first java code  RSS feed

 
ben istaharov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I WANT THIS PROGRAM TO get 3 numbers and show the biggest one.
what is wrong?





here is what the program says:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
This method requires a body instead of a semicolon

at main.main(main.java:4)


thanks
Ben
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37474
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben,
Welcome to CodeRanch! I added code tags to make the post easier to read.

It looks like you are missing braces. For example:


The braces are how Java knows which parts of the code go together. In other words, where things like methods and classes start and end. They are optional around if statements when there is a single statement. But they aren't optional all over.
 
ben istaharov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here it is and its still not working


public class main {

public static void main(String[] args) {

int Num1, Num2, Num3;
int temp;
Num1 = BasicIO.ReadInteger("Enter First Number: " );
Num2 = BasicIO.ReadInteger("Enter Secend Number: " );
Num3 = BasicIO.ReadInteger("Enter Third Number: " );

if (Num1 >= Num2 ) temp = Num1; else temp = Num2;

if (Num3 >= temp ) System.out.println("Biggest Num: " + Num3);

else

System.out.println("Biggest Num: " + Num3); } }



Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "}" to complete ClassBody

at main.main(main.java:18)


 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ben istaharov wrote:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "}" to complete ClassBody

at main.main(main.java:18)


One of the features of IDEs, is that it allows you to run programs that don't compile properly. Please don't use this feature. Make sure everything compiles before running them.

So, please compile the program, and show us the error from the compiler -- and not the error generated while running a program that didn't compile.


To answer your question... Do you have balanced curly braces? For each open brace, you need a close brace.

Henry
 
ben istaharov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where is the compiler button?
i used to pclick the run button before.

i have 4 braces.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37474
539
Eclipse IDE Java VI Editor
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try compiling it from the command line. This is something you need to learn how to do.

The code you posted most recently looks good to me - I can't compile it because I don't have your BasicIO class available, but if i comment out the lines, it does compile and run. If you are getting and error about braces, then you are not compiling the code you think you are.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ben istaharov wrote:where is the compiler button?
i used to pclick the run button before.

i have 4 braces.



Yeah, this is one of the reasons why we don't recommend starting with an IDE (for beginners) -- it hides access to the compiler from you. The problem with the compile error message at run time, is that it is the error first encountered while running the program. It may not be the first error encountered by the compiler. It may be one of the later errors -- where the compiler is already confused, and generating incorrect error messages.

Running the java compiler directly, you can quickly see which is the first compiler error. With the IDE, it is probably best to use the editor. Go to the top of the file, and slowly work your way down, until you hit the first red flag. There should be a tooltip that will show the error. BTW, I am assuming Eclipse, but other IDEs should be similar.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!