How do i get the average of a group of numbers when trying to run a program, i already have the public static void and the java scanner, also the system.out.println introducing the group name and how many grades i should insert into the program, now how do i make the program show me the group with the higher average, and how many grades went over a certain point? Serious answers please
|
Java
java coding assistance |
|
import java.util.Scanner;//start class
public class Assignment {//start main public static void main(String[] args) {//start main Scanner input = new Scanner(System.in); System.out.println("[Computer Science Classroom1A]"); //declare variables int lowest=0,highest=101,average=0,total=0; int grade; //for loop to take user input for (int i=1;i<=5;i++){ System.out.println("Please enter Studentgrade:"+i); grade=input.nextInt(); //do maths get total total=total+grade; //if statements to get highest to lowest if(grade>=highest){ highest=grade; }//end if if(grade<=lowest){ lowest=grade; }//end if }//end for loop //do maths get average average=total/5; //final printout System.out.println("The HIGHESTGRADE is:"+highest); System.out.println("The LOWESTGRADE is:"+lowest); System.out.println("The TOTALGRADE is:"+total); System.out.println("The AVR GRADE is"+average); }//end main }//end class I don't know how to add a while loop and a for loop together in the same program to use for each class, and idk how to get the highest or lowest, can you help?
Nov 7, 2017 12:43 PM
(This post was last modified: Nov 7, 2017 12:54 PM by UB3R5W4G0V3RL0RD.)
(Oct 25, 2017 06:10 AM)Dimlead Wrote: snippity snip (Click to View) Please use the "[code]" tags for code, or people will not want to read your code. This is completely disregarding the formatting you use for the code, which should also try to be neat. Import is to not use way to many redundant comments ("End of class") and to properly indent. Using "Egyptian Brackets" is simply a matter of preference. Egyptian Brackets (Click to View) Here: PHP Code |
|
|




![[Image: xwnI9Yg.png]](https://i.imgur.com/xwnI9Yg.png)