LoginSignup
1
1

More than 5 years have passed since last update.

10人の点数と偏差値を良い順に表示し、平均点で区切り線

Last updated at Posted at 2016-03-03

10人の点数を入力すると、
点数が良い順に並べかえ、素点と偏差値を表示する。
また平均点で区切り線を入れる。

1人目の点数は?10
2人目の点数は?100
3人目の点数は?20
4人目の点数は?90
5人目の点数は?30
6人目の点数は?80
7人目の点数は?40
8人目の点数は?70
9人目の点数は?50
10人目の点数は?60
素点100点 偏差値65.66698903601281
素点90点 偏差値62.18543591689885
素点80点 偏差値58.70388279778489
素点70点 偏差値55.22232967867093
素点60点 偏差値51.74077655955698
--------平均点55.0---------
素点50点 偏差値48.25922344044302
素点40点 偏差値44.77767032132907
素点30点 偏差値41.29611720221511
素点20点 偏差値37.81456408310115
素点10点 偏差値34.33301096398719

Sortscore.java
import java.util.Scanner;
class Sortscore {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int i,n[]=new int[10];

        for(i=0;i<n.length;i++){
            System.out.print(i+1 +"人目の点数は?");
            n[i]= scan.nextInt();
        }

        int j,k;

        for(i=0;i<n.length-1;i++){
            j=n.length-2-i;

            for(k=0;k<j+1;k++){
                if(n[k] >= n[k+1]){
                }else{
                int l=0;
                l = n[k];
                n[k] = n[k+1];
                n[k+1] = l;
                }
            }
        } 

        double average = Ave(n);
        double bunsan = Bunsan(n);
        double hensachi = 0;

        for(i=0;i<n.length;i++){
            if(bunsan == 0){
                hensachi = 50.0;
            }else{ 
                hensachi = (double)(n[i] - average)/Math.sqrt(bunsan) * 10 + 50; 
            }

            if(n[i] >= average){
                System.out.println("素点"+ n[i] + "点  偏差値" + hensachi);               
            }
        }

        System.out.println("--------平均点" + average + "---------");

        for(i=0;i<n.length;i++){
            if(bunsan == 0){
                hensachi = 50.0;
            }else{ 
                hensachi = (double)(n[i] - average)/Math.sqrt(bunsan) * 10 + 50; 
            }

            if(n[i] < average){
                System.out.println("素点"+ n[i] + "点  偏差値" + hensachi);               
            }
        }
    }

    private static double Ave(int[] n){
        int total=0,i;
        for(i=0;i<n.length;i++){
            total = total + n[i];
        }
        return (double)total/n.length;
    }

    private static double Bunsan(int[] n){
        int j=0,i;
        for(i=0;i<n.length;i++){
            j = j + (int)Math.pow(n[i],2);
        }
        return (double)j/n.length - Math.pow(Ave(n),2);
    }
}

とりあえずどうにかできるようにした。
並べ替えはバブルソートです。

平均点での区切り線。とても冗長な内容を記述してしまっていると思います。
手直し予定。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1