I am trying to add values from the keyboard in my string type array. For this, I first take input the array size and then create a string array according to the size. But when I try to add values to the array it always takes size-1
values only. When tried to print the array I found that value at 0 index is always null.
suppose if i give input
3
we
are
fine
It reads only 3 we are
and prints we are
. but output should be we are fine
.
where is my fault?
public class SparseArrays {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int size= in.nextInt();
String [] input= new String[size];
for(int i=0;i<input.length;i++){
input[i]=in.nextLine();
}
for(int i=0;i<input.length;i++) {
System.out.print(input[i]);
}
}
}