Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package statistics;
- /**
- *
- * @author caranra
- */
- public class Statistics {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int[] a1= new int [20];//initialize an array w/ 20 values
- a1 =randomize(a1,100); //the array will have random points, 0-100
- display(a1);//the array will be displayed in the outpost
- a1=sort(a1);//sorts the arrays into numerical order
- display(a1);//displays the sorted array
- System.out.println("The average for Array 1 is: " +average(a1) );
- }
- public static int[] randomize(int[] a, int max) { //creates a ray that is filled with points at random
- for(int i=0; i< a.length; i++) {
- a[i]=(int)(Math.random()*max)+1;
- }
- return a;
- }
- public static void display(int[] a) {
- for(int i=0;i<a.length;i++){
- System.out.print(a[i]+" ");
- }
- System.out.println(" ");
- }
- public static double average(int[]a){
- double sum=0;
- for(int i=0; i<a.length;i++){
- sum+=a[i]; //sum=sum+a[i]
- }
- return sum/a.length;
- }
- private static int[] sort(int[]a){
- int size =a.length; //# of values in the array
- int[]sorted=new int[size];
- int min=0;
- for(int i=0; i<a.length;i++){
- min=0;
- for(int j=0;j<a.length;j++){
- if(a[j]<a[min]){
- min=j;
- }
- }
- sorted[i]=a[min];
- a[min]=5000;
- }
- return sorted;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement