Thursday, February 2, 2012

Challenge 042’s Solution

To complete Challenge 42, the following code must be placed into BlueJ™:

import java.util.Arrays;
public class Challenge042
{
    public static void main(String[] args)
    {
        int[] scores = {97,56,78,88};
        Arrays.sort(scores);
        System.out.println("Original Scores:");
        for(int x = 0; x <= scores.length - 1; x++)
        {
            System.out.println(scores[x]);
        }
        System.out.println();
        curveScores(scores);
    }
    public static void curveScores(int[] s)
    {
        int[] sortedScores = s;
        Arrays.sort(sortedScores);
        int curve = 100 - sortedScores[sortedScores.length - 1];
        System.out.println("Curved Scores:");
        for(int x = 0; x <= s.length - 1; x++)
        {
            System.out.println((s[x] + curve));
        }
    }
}

−Phoenix

1 comment:

  1. Effective approach involving the Arrays class from the util library, good work. 600 XPs awarded for this completion.

    ReplyDelete