Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

java coding assistance

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
Post your code onto github so we can help you...Or post it anywhere.
[Image: xwnI9Yg.png]
yes, show us what you’ve started already and we can try to help you from there.
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?
(Oct 25, 2017 06:10 AM)Dimlead Wrote:  snippity snip (Click to View)
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?

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

<?php 
import java
.util.Scanner;

public class 
Assignment {

public static 
void main(String[] args) {

    
Scanner input = new Scanner(System.in);
    
int lowest = 0, highest = 101, average = 0, total = 0;
    
int grade;

    
System.out.println("[Computer Science Classroom1A]");

    
//for loop to take user input
    
for (int i = 1;i <= 5; i++){
        
System.out.println("Please enter Studentgrade:" + i);
        
grade = input.nextInt();

        
total = total + grade;

        
//if statements to get highest to lowest
        
if(grade >= highest){
            
highest = grade;
        }
        if(
grade <= lowest){
            
lowest = grade;
        }
    }

    
//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);

   }
} 


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by MesaGFXMay 21, 2019 10:02 AM 1 165 May 21, 2019 10:02 AM
Last Post: A_P_T
[C] by ZinkApr 2, 2018 05:23 PM 3 199 Apr 2, 2018 05:23 PM
Last Post: Annabelle Lee
[Java] by DimleadDec 4, 2017 12:42 AM 3 187 Dec 4, 2017 12:42 AM
Last Post: Ozgin