Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.
java code problem
Name: hye345 Date: January 13, 2005 at 22:40:34 Pacific OS: windows xp home edition w CPU/Ram: 2.53 ghz, 512 ram
Comment:
i type the following code in java:
public class Book { public static void main(String [0] args) public static void main(String [1] args) { System.out.println("Title: " + args[0]); System.out.println("Author: " + args[1]); } }
in the command line, i type java book "Green eggs and ham" "dr seusse"
it wont compile, and im in the rite directory. what am i doing wrong?
Name: bamakhrama Date: January 14, 2005 at 01:36:55 Pacific
Reply:
Hi, 1) you can NOT have 2 main functions ins the same program. 2) No need to specify the length of the args[] array. It will be set automatically by the OS. Here is the working code:
public class Book
{
public static void main(String[] args)
{
System.out.println("Title: " + args[0]);
System.out.println("Author: " + args[1]);
}
}
-- mohameda@ieee.org
0
Response Number 2
Name: hye345 Date: January 14, 2005 at 15:58:48 Pacific
Reply:
what would i have to type into a command line for it to show up?
0
Response Number 3
Name: hye345 Date: January 14, 2005 at 16:04:00 Pacific
Reply:
i type java book "green eggs and ham" "dr seusse" and it says expeption in thread "main" java.lang.NoClassDefFoundError: book
0
Response Number 4
Name: hye345 Date: January 14, 2005 at 18:02:03 Pacific
Summary: Hi, This may be a stupid question, but does anyone know a place online to test simple java code? I can't install anything on this computer and my test environment doesn't arrive until next week. ...
Summary: My project source code generate a A.java file with 6 classes defined in it, we currently need to compile each class manurarly, and the put the 6 .class file into some applet. Is there any super heros ...