CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Java Code

  1. #1
    Join Date
    Apr 1999
    Location
    Houston,Tx
    Posts
    9

    Java Code

    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.






  2. #2
    Join Date
    Apr 1999
    Location
    Bangalore,India
    Posts
    43

    Re: Java Code

    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...


  3. #3
    Join Date
    Apr 1999
    Location
    Houston,Tx
    Posts
    9

    Re: Java Code

    Hi,

    Thanks for the reply.Actually I did not add the main in the source code.I got it now.

    Deepa


  4. #4
    Join Date
    May 2000
    Posts
    2

    Re: Java Code

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured