Tuesday, 29 September 2015

Java Scanner Class Example

/**
 *
 */
import java.io.*;
import java.util.*;
/**
 * @author U0123154
 *
 */
public class DynamicArray {

/**
* @param args
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i = Integer.parseInt(br.readLine());
int array[] = new int[i];
//Accept the values dynamically
Scanner sc = new Scanner(System.in);
for(int k=0;k<i;k++){
array[k] = sc.nextInt();
System.out.println("The values are " +array[k]);
}
}

}


Output:-
5
1 2 3 4 5
The values are 1
The values are 2
The values are 3
The values are 4
The values are 5

No comments:

Post a Comment