Hack Forums
[Java] java coding assistance - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] java coding assistance (/showthread.php?tid=5742347)



java coding assistance - Dimlead - Oct 24, 2017

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


RE: java coding assistance - Linxy - Oct 24, 2017

Post your code onto github so we can help you...Or post it anywhere.


RE: java coding assistance - maranathabuton - Oct 24, 2017

yes, show us what you’ve started already and we can try to help you from there.


RE: java coding assistance - Dimlead - Oct 25, 2017

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?


RE: java coding assistance - UB3R5W4G0V3RL0RD - Nov 7, 2017

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

   }
}