User:JOptionPane/monobook.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin can be added at User:JOptionPane/monobook.css. |
import java.util.*;
public class SumAverageScores
{
public static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
double a = inputDouble("Input first score");
double b = inputDouble("Input second score");
double c = inputDouble("Input third score");
double d = inputDouble("Input fourth score");
double e = inputDouble("Input fifth score");
int v = (int)(a + 0.5);
int w = (int)(b + 0.5);
int x = (int)(c + 0.5);
int y = (int)(d + 0.5);
int z = (int)(e + 0.5);
outputAverage(v,w,x,y,z);
}
public static double average(double x1, double x2, double x3, double x4, double x5) {
return (x1 + x2 + x3 + x4 + x5) / 5.0;
}
public static void outputAverage(double x1, double x2, double x3, double x4, double x5) {
System.out.printf("The average of %2f, %2f, %2f, %2f, and %2f is %2f\n"
,x1,x2,x3,x4,x5,average(x1,x2,x3,x4,x5));
}
public static double inputDouble(String prompt) {
System.out.println(prompt);
return console.nextDouble();
}
}