Hello word !
i was doing some java exercices, and there is one who ask to write a program that asks the user to enter the size and values (of type string) of an array and display them on the screen.
this is the code :
public static void main(String[] args) {
Scanner clv =new Scanner(System.in);
System.out.println("entrez la taille de T ");
int n=clv.nextInt();
String T[] = new String[n];
clv.nextLine(); //why ??
for(int i=0;i<n;i++){
System.out.println("entrez le contenue de T["+i+"]");
T[i] =clv.nextLine();
}
for(int j=0;j<n;j++){
System.out.println("T["+j+"] = "+T[j]);
}
}
when i delete the line on red color the first element T[0] is saved on T[1], T[1] on T[2] and so on... i don't understand why?
Thank you for read and sorry for my bad English :)