I'm missing something in accepting input from keyboard and store it in array.
This is what I tried:
public static void main(String[] args) {
System.out.println("Hello World");
Scanner obj=new Scanner(System.in);
System.out.println("enter sentence ");
String[] inputArray = new String[10];
int i = 0;
while (obj.hasNext()){
String word = (String) obj.next();
inputArray[i] = word;
System.out.println("word is " + word);
System.out.println("array is " + inputArray[i]);
}
System.out.println("final array is " + inputArray); //This line doesn't print. Why ?
}
Why I can't print the array after while loop?