r/javahelp • • Apr 16 '16

why wont this average program work?

http://pastebin.com/W104SbF0

why wont it show the average what do i need to change in my for loop? if i use for each loop it works but i dont wanna use a for each loop.

0 Upvotes

2 comments sorted by

1

u/[deleted] Apr 16 '16

nm i got it had to use numbers[i]. duh

2

u/[deleted] Apr 16 '16

You know integers are whole numbers? You'll want to use a float or double.

You also need to cast it to a floating point e.g.

float avg = (float) (1+2+3+4+5)/5

also you need to use numbers[i], not i