# more efficient way to make this??? [LOOK]

• 09-09-2011, 12:39 AM
Green
more efficient way to make this??? [LOOK]
Code:

```import java.util.Scanner; public class first {         public static void main (String [] args){                 Scanner reader = new Scanner(System.in);                 int total_age;                 int age1, age2, age3, age4, age5, age6, age7, age8, age9, age10, age11, age12, age13, age14, age15, age16, age17, age18, age19;                 int mean_age;                 System.out.print("Enter the age of the students ");                 age1 = reader.nextInt();                 age2 = reader.nextInt();                 age3 = reader.nextInt();                 age4 = reader.nextInt();                 age5 = reader.nextInt();                 age6 = reader.nextInt();                 age7 = reader.nextInt();                 age8 = reader.nextInt();                 age9 = reader.nextInt();                 age10 = reader.nextInt();                 age11 = reader.nextInt();                 age12 = reader.nextInt();                 age13 = reader.nextInt();                 age14 = reader.nextInt();                 age15 = reader.nextInt();                 age16 = reader.nextInt();                 age17 = reader.nextInt();                 age18 = reader.nextInt();                 age19 = reader.nextInt();                 total_age = age1 + age2 + age3 + age4 + age5 + age6 + age6 + age8 + age9 + age10 + age11 + age12 + age13 + age14 + age15 + age16 + age17 + age18 + age19;                 mean_age = total_age / 19;                 System.out.println(mean_age);         } }```
can anyone think of a smarter way to write this? its asking for 19 students ages and then finding the mean of them...
• 09-09-2011, 01:05 AM
Norm
Re: more efficient way to make this??? [LOOK]
A loop with the input values summed in the loop. If there is no need for the individual ages after adding them to the total, don't save them in variables.
• 09-09-2011, 01:09 AM
Junky
Re: more efficient way to make this??? [LOOK]
I looked but wasn't impressed.
• 09-09-2011, 01:16 AM
Green
Re: more efficient way to make this??? [LOOK]
Quote:

Originally Posted by Junky
I looked but wasn't impressed.

that would be why i am asking for help, because i am a beginner and posting in the New To Java section, you retard.

Quote:

Originally Posted by Norm
A loop with the input values summed in the loop. If there is no need for the individual ages after adding them to the total, don't save them in variables.

an example would look like?
• 09-09-2011, 01:29 AM
Junky
Re: more efficient way to make this??? [LOOK]
My previous post was in response to you placing LOOK in the title. This is the same as those that place URGENT in the title. You only do it for one reason: draw attention to yourself in the hop of gaining preferential treatment. Well you are no more important than anyone else asking for help. People will offer help if and when they like. I have now made 2 posts in this thread and neither have offered you any help. So pimping your thread has actually reduced your chances of getting help not increased it. Many others feel the same way as I do.

Feel free to get all offended, throw a hissy fit and hurl abuse my way. That just further decreases your chances of getting help.
• 09-09-2011, 01:33 AM
Green
Re: more efficient way to make this??? [LOOK]
pfft. i will - rep you and you must think that i care if you wont help me. i am sure someone will offer advice sooner or later.
/trollolloooooolll
• 09-09-2011, 01:41 AM
Junky
Re: more efficient way to make this??? [LOOK]
Yes I'm sure someone will because you are so fabulous that you can abide by your own rules. Such a rebel.
• 09-09-2011, 01:45 AM
Green
Re: more efficient way to make this??? [LOOK]
Quote:

Originally Posted by Junky
Yes I'm sure someone will because you are so fabulous that you can abide by your own rules. Such a rebel.

gtfo my thread, spammer. 2.4k posts since January LMAO
• 09-09-2011, 01:46 AM
sunde887
Re: more efficient way to make this??? [LOOK]
I wish we had a troll face smiley. @op: Don't get offended, just take his advice and move on. Seeing [LOOK], URGENT, SUPER DUPER IMPORTANT, won't get your post help any quicker(and it may hurt you).
• 09-09-2011, 01:57 AM
Norm
Re: more efficient way to make this??? [LOOK]
set total and count to 0