I am new to Java and I was looking to get a hold of a loop in java. I have the code below for trial and the problem is the for loop in the main method prints everything correct on the 1st iteration like this:
CMD>Please enter the name of person 1
CMD>ber
CMD>
CMD>sex of person1
CMD>male
CMD>
CMD>age of person1
CMD>23
but on the second iteration this happens
CMD>Please enter the name of person 2
CMD>sex of person2
CMD>
jumpes the first name enquiry the code is below
I have gone thru all trials and debugging
class MID {
public static void main(String args[]) {
person [] persons= new person[3];
Scanner input= new Scanner(System.in);
for (int i = 0; i <=2 ; i++) {
persons[i]= new person();
System.out.println(" Please enter the name of person " + (i+1));
persons[i].P_name = input.nextLine();
System.out.println(" sex of person" + (i+1));
persons [i].P_sex= input.nextLine();
System.out.println(" age of person" + (i+1));
persons[i].P_age =input.nextInt();
}
...
I want to input multiple names. there is a class person with
String P_name, P_sex;
int P_age;
metho void P_data ()
System.out.println(" The person named " + P_name + "is " + P_age + " years old and is a " + P_sex);