• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hey guys im new and i have a problem  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey im new to these forums but java in general. Im not doing java for school or anything but just in my leisure time. Im in grade 9, and im learning for a guy on youtube called thenewboston. Is he good. But im also reading a book alongside this and my dad is a programmer so i rely on him for help when i need it. Anyway i am using arrays and i am trying to make a program that has a method to average the values in an array and a method to display the averages for a certain subject.

my problem is that when using the "average" method the average is correct however it ends up being zero in the "display" method. this is the output
The average for Science is 0
The average for Math is 0
The average for French is 0
60
72
69

thanks for your help and sorry if im noob and point out what im doing wrong.
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Hint: If you try making a phone call from your phone, before inserting the battery, how many phone calls can you make? 0!!! (because you did not follow the proper sequence)
Switch

to

Do you see anything different? Can you understand why?
 
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also it is confusing to try to get averages out of an int[][]. Much easier to use an int[]. You would do better to create Subject classes, with name, marks (array) and average fields. You would of course have to calculate the averages when you create the objects, from the marks arrays.
There is something not right about your averaging method. Anything which uses [column + 1] (except for sorting) is guilty until proven innocent. Use a for-each (=enhanced for) loop to add the values in the array. Use anArray.length as the divisor. Work out why the average of this array comes to 78, not 79:And welcome to the Ranch again
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!