Hello world

printing hello world

Page 1 of 1

1 Replies - 720 Views - Last Post: 19 July 2008 - 11:02 PM Rate Topic: -----

#1 elzajose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-July 08

Hello world

Post icon  Posted 19 July 2008 - 10:53 PM

hi
public class hello
{
public static void main(String args[])
  {
int i;
System.out.println("command line arguments\n----------------------------------");
if(args.length==0)
   System.out.println("No command line arguments specified");
else
  {
for(i=1;i<=args.length;i++)
    System.out.println(+i+". "+args[i]);
}
  }
}


This code is showing run time error
elza

** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Hello world

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: Hello world

Posted 19 July 2008 - 11:02 PM

Like all arrays, their subscripts begin at 0. So you want your loop to from 0 to less than the length.

// Start at zero and go to one less than the args array length
for(i=0;i<args.length;i++)  



That will solve the problem. Enjoy!

"At DIC we be arg displaying code ninjas... we also display other things but then the cops come" :snap:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1