hey guys the aim is to have 5 users to input data into their program and to output 5 people that have entered their details respectively. any hints would be great =)
my program needs =
a loop so that it ask 5 times users name age etc etc
and then counts ther number of users entered..
i just cant get my head around it. i know i need a loop inside a loop but i cant figure out how i can do it. really would appreciate anyones help to get my program working i really would.
//A Program to test my Person Class Program import java.util.*; public class Person { // Tests the methods of the Person File public static void main(String [] args) { int [] i = new NewPerson[5]; Scanner input = new Scanner(System.in); for (int i = 0; i <= i.length ; i++) { System.out.print("Please enter your Forename "); String FName = input.next(); System.out.print("Please enter your Surname "); String LName = input.next(); System.out.print("Please enter your Age "); int AAge = input.nextInt(); System.out.print("Please enter your Height "); int AHeight = input.nextInt(); PersonTest person1 = new PersonTest(FName, LName, AAge, AHeight); person1.format(); System.out.println("The number of Persons entered are " + (i)); } } }
//A Program to test my Person Class Program import java.util.*; public class PersonTest { // Tests the methods of the Person File public static void main(String [] args) { Scanner input = new Scanner(System.in); //Creates an Array that counts the number of Persons in the Program int [] countPerson = new int [5]; for (int i = 0; i < countPerson.length ; i++) { //System.out.print(i + ","); System.out.print("Please enter your Forename "); String FName = input.next(); System.out.print("Please enter your Surname "); String LName = input.next(); System.out.print("Please enter your Age "); int AAge = input.nextInt(); System.out.print("Please enter your Height "); int AHeight = input.nextInt(); } //Person person1 = new Person(FName, LName, AAge, AHeight); //person1.format(); //System.out.println("The number of Persons entered are " + (i)); } }