I have written a small program to improve my Java skills. I am trying to get the list of names and print the same using while loop. But the while loop which gets input is not terminating upon reaching the limit. My while condition looks okay. But I'm not sure, what is going wrong. Here is the code:
import java.io.DataInputStream;
import java.io.IOException;
public class MyTestProgram {
public static int count;
public static DataInputStream din;
public static String names[];
public static void main(String[] args) throws NumberFormatException, IOException {
din = new DataInputStream(System.in);
int counter = 0;
System.out.print("Enter the numer of persons: ");
count = Integer.parseInt(din.readLine());
names = new String[count];
System.out.println("Enter the names one by one:");
while (counter < count) {
names[counter] = din.readLine();
counter = counter++;
}
System.out.println("List of names entered:");
while (counter < count) {
System.out.println(names[counter]);
counter = counter++;
}
}
}