Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class meanModeMedianRange {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- double sum = 0;
- int i = 0;
- double element = 0;
- double count = 0;
- System.out.println("Welcome to the MEAN, MEDIAN, RANGE program");
- System.out.println("Please enter the length of your list: ");
- int length = input.nextInt();
- double[] myList = new double[length];
- for(i = 0; i < myList.length;i++){
- System.out.println("Please enter your number");
- double number = input.nextDouble();
- myList[i] = number;
- }
- System.out.println("Your list reads as below:");
- //Prints the list(Unsorted)//
- for(i = 0; i < myList.length; i++){
- System.out.println(myList[i]);
- }
- //Finds the average of the list//
- for(i = 0; i < myList.length; i++){
- sum+=myList[i];
- }
- Arrays.sort(myList);
- System.out.println("This is your sorted list");
- //Prints the list(Sorted)//
- for(i = 0; i < myList.length; i++){
- System.out.println(myList[i]);
- }
- //Finds the mode of the list//
- for(int k=0;k<myList.length;k++){
- double tempElement = myList[k];
- double tempCount = 0;
- for(int j=0;j<myList.length;j++){
- if(myList[j] == tempElement){
- tempCount++;
- }
- if(tempCount > count){
- element = tempElement;
- count = tempCount;
- }
- }
- }
- System.out.println("The mean/average of your list is: " + sum/myList.length);
- int median = myList.length/2;
- System.out.println("The median of your list is: " + myList[median]);
- double firstnum = myList[0];
- double lastnum = myList[myList.length-1];
- System.out.println("The range of your numbers is: " + (lastnum-firstnum));
- System.out.println("The most frequent number in your array is " + element + ", which appears " + count + " times");
- }
- }
Add Comment
Please, Sign In to add comment