Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- /*
- * Kendred Thompson
- * 4th Period
- * CS 2
- * Skater Scores
- */
- public class Program {
- public static void main(String[] args) {
- double [] [] scores = { {5.6, 3.5, 5.9, 5.4, 5.1},
- {4.4, 5.4, 5.4, 5.8, 5.9},
- {4.5, 2.4, 4.3, 5.2, 4.5},
- {4.4, 5.2, 5.8, 4.9, 5.6},
- {5.3, 4.2, 5.5, 4.9, 4.9},
- {5.9, 5.6, 0.7, 4.4, 6.0},
- {5.1, 5.8, 3.2, 4.9, 2.8}};
- //Helps round scores to 1 decimal place
- DecimalFormat df = new DecimalFormat("#.0");
- for(int skater = 0; skater < scores.length; skater++) {
- System.out.println("Scores for Skater #" + (skater + 1) + ":");
- double sum = 0; //Variables of the code
- double max = scores[skater][0];
- double min = scores[skater][0];
- for(int judge = 0; judge < scores[skater].length; judge++) {
- sum = sum + scores[skater][judge];
- System.out.print(scores[skater][judge] + "\t");
- if(scores[skater] [judge] > max) { //Finds the Maximum
- max = scores[skater][judge];
- }
- if(scores[skater] [judge] < min) { //Finds the Minimum
- min = scores[skater][judge];
- }
- }
- double avg = (sum - min - max) / (scores[skater].length-2);
- System.out.println();
- System.out.println("Average: " + df.format(avg));
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement