Welcome to Lab 5

By the end of this Lab you should be able to do the following.

Lab Topics

This is a brute force way to see which number is the largest but the code is simple to understand. It is not unusual to have to choose between an elegant algorithm that is hard to implement or a simple algorithm that takes a lot of code

/**
 * Largest will find the largets of 3 numbers entered by the user.
 * The 3 numbers must be integers less than or equal to MAX_VALUE,
 * a constant holding the maximum value an int can have, 2147483647
 * and greater than or equal to MIN_VALUE, a constant holding the 
 * minimum value an int can have, -2147483648.
 * 
 * @author Allan Kranz 
 * @version 1.0.0.0
 * date 11 Feb 2011
 */

import java.util.Scanner;

public class Largest
{
    // instance variables - replace the example below with your own
    private int x;
    private int y;
    private int z;

    public static void main(String[] args){
        Largest myProgram = new Largest();
        myProgram.run();
    }
    
    /**
     * Constructor for objects of class Largest
     */
    public Largest(){

    }

    /**
     * run() asks the user for three ints and displays the largest
     * 
     * @param  none
     * @return  none
     */
    public void run(){
        Scanner in = new Scanner(System.in);
        System.out.print("Please enter 3 numbers with spaces between them ");
        
        x = in.nextInt();
        y = in.nextInt();
        z = in.nextInt();
        
        if(x <= y && y <= z){
		    System.out.println("The biggest is "+z);
        }
        
        if(x <= z && z <= y){
          	System.out.println("The biggest is "+y);  
        }
        
        if(y <= x && x <= z){
          	System.out.println("The biggest is "+z);  
        }

        if(y <= z && z <= x){
          	System.out.println("The biggest is "+x);  
        }

        if(z <= x && x <= y){
          	System.out.println("The biggest is "+y);  
        }
     
        if(z <= y && y <= x){
          	System.out.println("The biggest is "+x);  
        }
        return;
    }
}


 

Output of sample program

MODE*

In statistics, the mode is the value that occurs most frequently in a data set or a probability distribution. The mode is in general different from the mean and median, and may be very different for strongly skewed distributions. The mode is not necessarily unique, since the same maximum frequency may be attained at different values. The most ambiguous case occurs in uniform distributions, wherein all values are equally likely.

MEDIAN*

In probability theory and statistics, a median is described as the numeric value separating the higher half of a sample, a population, or a probability distribution, from the lower half. The median of a finite list of numbers can be found by arranging all the observations from lowest value to highest value and picking the middle one. If there is an even number of observations, then there is no single middle value; the median is then usually defined to be the mean of the two middle values

MEAN*

For a data set, the mean is the sum of the values divided by the number of values.

* wikipedia

Programming Problem

Find the mode, median and mean of 5 numbers entered by the user. You are not allowed to use an ArrayList or any other data structure.