Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

convert'String args[]'

  Asked By: Nicole    Date: May 15    Category: Java    Views: 543
  

im writing a program that im using an integer.parseInt, which
needing to convert'String args[]' my code should print:



Index value
0 0
1 0
2 0
3 0

when I call the InitArray from the command via:

It should print:

java InitArray 4.

heres my code any suggestions would be great.



public class InitArray
{
public static void main( String args[] ) {
if ( args.length != 4 )
System.out.println( "java InitArray 4" );
else {

int arrayLength = Integer.parseInt( args[ 0 ] );
int array[] = new int[ 4 ];

int initialValue = Integer.parseInt( args[ 1 ] );
int increment = Integer.parseInt( args[ 2 ] );

for ( int counter = 0; counter < array.length; counter++ )
array[ counter ] = initialValue + increment *
counter;
System.out.printf( "%s%8s\n", "Index", "Value" );

for ( int counter = 0; counter < array.length; counter++ )
System.out.printf( "%5d%8d\n", counter, array[
counter ] );
}
}
}



Share: 

 

2 Answers Found

 
Answer #1    Answered By: Fatih Farooq     Answered On: May 15

First: your post is incomplete. The whole call  of the class  is missing.
Your post is puzzling in structure; in other words: some parts seem to
have got mixed up, their order seems to be wrong.

Second: why do you require the user to enter four parameters if only
three are used?

Third: I've read the post three times, but still I don't understand
what it's supposed to do. What do you have in mind? This was not clear
to me.

Fourth: a short greeting (and be it only the obvious hated "HI") would
not hurt. Neither would a short closing greetings (regards, thanks...
whatever).

 
Answer #2    Answered By: Isaac Evans     Answered On: May 15

i think u r not running the program  with proper values of arguments
u run the application with atlist 5 argumenf or remove the if condition and run
it with atlist 3 argument becouse in your code  u r using args[] of main  method
try it i think it will help u out

 
Didn't find what you were looking for? Find more on convert'String args[]' Or get search suggestion and latest updates.




Tagged: