Saturday, July 11, 2015

Program to create Array of Dynamic Size & take values from Command Line

import java.util.Scanner;

class Demo{
public static void main(String[] args){
int no = Integer.parseInt(args[0]);
String[] arr = new String[no];

for(int i = 0 ; i< no;i++){
arr[i] = args[i+1];
System.out.println(arr[i]);
}


}
}


How to run:
java Demo 3 vadodara anand delhi

Output:
vadodara
anand
delhi



No comments:

Post a Comment