Here is my code. The goal is to enter basic information (age, name, gender) for x number of patients.
public static void main(String[] args) { int numPatients = 2; int[] age = new int[numPatients]; String[] gender = new String[numPatients]; String[] name = new String[numPatients]; Scanner in = new Scanner(System.in); for (int i = 0; i < numPatients; i++) { System.out.println("Enter name of patient " + (i+1)); name[i] = in.nextLine(); System.out.println("Enter gender (male/female) of patient " + (i+1)); gender[i] = in.nextLine(); System.out.println("Enter age of patient " + (i+1)); age[i] = in.nextInt(); }
The problem I am facing is when the loop goes to the second variable, that is, I cannot enter a value for the name of the patient. It seems that he skips the entrance there and goes directly to the next entrance, which is a floor.
Enter name of patient 1 Mark Enter gender (male/female) of patient 1 Male Enter age of patient 1 34 Enter name of patient 2
Any idea why this is happening? Is it better to use a BufferedReader?
source share