Click to See Complete Forum and Search --> : Java Code
Deepa Natarajan
July 28th, 1999, 12:00 PM
1.
class ***{
System,out.println(" " + 2 +3 );
System,out.println(2 +3);
System,out.println(2 +3 + " ");
System,out.println(2 + " " +3 );
}
Gives error has : Type Expected.
2.class Test{
System.out.println( -1 * Double.NEGATIVE_INFINITY);
}
Does nor compile.
It would be helpful if I get an explanation.
varbsjava
July 29th, 1999, 04:20 AM
Hi,
First thing.
It is not System,out.println(); It is System.out.println();
Second one. Explain me what you tried. Because there is no main method for the JVM to call your classes.
Next one is u can't execute the statements in the way u have mentioned. First u have create a object of that class. Include these either in the constructor part or create a method and include these things in the method.
Or u can include these statements in the main block of the class. Main block is the one where the application starts.
For example
public class Test{
public static void main(String[] args){
System.out.println("Hai Mr.X");
}
}
So after compilation when u say "java Test" ,
"Hai" is printed.
Go thru basic java fully and start the coding.
regards,
arun...
Deepa Natarajan
July 29th, 1999, 09:31 AM
Hi,
Thanks for the reply.Actually I did not add the main in the source code.I got it now.
Deepa
ivanai
May 3rd, 2000, 02:02 AM
Here is the corrected program:
class ***{
public static void main(String args[]){
System.out.println(" " + 2 + 3 );
System.out.println(2 + 3);
System.out.println(2 + 3 + " ");
System.out.println(2 + " " + 3 );
}
}
Compare it with what you have done than read some books ("Thinking in Java" by
Bruce Eckel is recommended) and than you'll find why you need main method in
your class. Also you cannot use comma (,) when you are refering to
System.out.println()
You are missing the same piece of code in your second class. So here is correct version
class Test{
public static void main(String args[]){
System.out.println( -1 * Double.NEGATIVE_INFINITY);
}
}
Enjoy learning Java it is very interesting
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.