Computing.Net > Forums > Programming > java code problem

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

java code problem

Reply to Message Icon

Original Message
Name: hye345
Date: January 13, 2005 at 22:40:34 Pacific
Subject: java code problem
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?


Report Offensive Message For Removal


Response Number 1
Name: bamakhrama
Date: January 14, 2005 at 01:36:55 Pacific
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 2
Name: hye345
Date: January 14, 2005 at 15:58:48 Pacific
Reply: (edit)

what would i have to type into a command line for it to show up?


Report Offensive Follow Up For Removal

Response Number 3
Name: hye345
Date: January 14, 2005 at 16:04:00 Pacific
Reply: (edit)

i type java book "green eggs and ham" "dr seusse" and it says expeption in thread "main" java.lang.NoClassDefFoundError: book


Report Offensive Follow Up For Removal

Response Number 4
Name: hye345
Date: January 14, 2005 at 18:02:03 Pacific
Reply: (edit)

it worked. thx.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you own an iPhone?

Yes
No, but soon
No


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge
Poll History




Data Recovery Software