java code help

insane

Weaksauce
Joined
Aug 17, 2006
Messages
83
I need help on a subtle problem in my java code. I writing a program for college admissions and I have all the computations figured out but I want to prompt the user to say

inforamtion for applicant #1:

<code>

information for applicant #2:

<code>

etc

the only thing changing is the number. I know i can loop it like this:

for (int i = 1; i <= 2; i++) {
System.out.println("Information for applicant #" + i + ":");
}

but that will run my computations in my code twice for each person. How can i have it where I'm not redundant but still be able to differentiate the number value?
 
Have the user enter the number of applicants they want to enter data for and use that in place of the "2" you put in your for-loop. There are other ways, of course. E.g. you could use a while loop and have it stop when the data entered by the user is an empty string, etc.
 
Use a counter instead of looping through the entire question again. You could do what amromousa suggested above and prompt the user for a # of applications or you could just start a counter at 1 and every time the user moves to the next application the counter variable increase by 1.
 
Back
Top