Results 1 to 11 of 11
- 09-08-2011, 11:39 PM #1
more efficient way to make this??? [LOOK]
can anyone think of a smarter way to write this? its asking for 19 students ages and then finding the mean of them...Java 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); } }
- 09-09-2011, 12:05 AM #2
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, 12:09 AM #3
Re: more efficient way to make this??? [LOOK]
I looked but wasn't impressed.
- 09-09-2011, 12:16 AM #4
- 09-09-2011, 12:29 AM #5
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, 12:33 AM #6
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, 12:41 AM #7
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, 12:45 AM #8
- 09-09-2011, 12:46 AM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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).
Last edited by sunde887; 09-09-2011 at 03:59 AM.
- 09-09-2011, 12:57 AM #10
Re: more efficient way to make this??? [LOOK]
set total and count to 0
loop until all input read
read input
add input to total
add 1 to count
end loop
average = total / count
- 09-09-2011, 01:01 AM #11
Re: more efficient way to make this??? [LOOK]
You really aren't very bright are you? Did you bother to read where I said that throwing a hissy fit and getting abusive further decreases your chances of getting help? Then right on cue you do that very thing. Why don't you complete the set and accuse me of having no life and living in my parents basement because I've never heard that one before.
Similar Threads
-
Tell me efficient way
By lkalaivanan in forum New To JavaReplies: 3Last Post: 08-11-2011, 11:36 AM -
Efficient image loading
By aburnett397 in forum Advanced JavaReplies: 0Last Post: 02-04-2011, 02:44 PM -
is there a more efficient way?
By Yakg in forum New To JavaReplies: 3Last Post: 01-23-2011, 05:32 PM -
Need some help with code. Make it more efficient.
By Meta in forum New To JavaReplies: 1Last Post: 03-22-2010, 08:21 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks