jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Java arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java arrays" Watch "Java arrays" New topic

Java arrays

Tharindu Priyath

Joined: Nov 01, 2012
Posts: 6
class Test03{
public static void main(String args[]){
int i = Integer.parseInt(args[0]);
switch (i)
case 1:
System.out.println("case 1");
case 2:
System.out.println("case 2");
This program shows Runtime error. Why?
What is athe meaning of this statement?
int i = Integer.parseInt(args[0]);
Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 75

args[0] is a command line argument that you give it when you run it.

If you look at the variable args, it signifies a string array. You're converting the string into an int.

Also, you should add break statements after each case, otherwise it's going to run through the whole list.

Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
Joel Christophel
Ranch Hand

Joined: Apr 20, 2011
Posts: 249

Upon the running of a program, it's possible to pass in String values to a program. String args[] is the array that holds the (optional) input values. Since you didn't pass anything to the program when you tried to run it, you got an error because you tried to use the value that you didn't pass in.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46362
To the Batmobile!! Java Tutorials!! Look here and here. I think the 2nd link will be more useful.
I agree. Here's the link: http://aspose.com/file-tools
subject: Java arrays
jQuery in Action, 3rd edition