logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    sfolax6776
    Aug 21, 2018
      ·  Edited: Aug 29, 2019

    6.3 How to find the average, maximum and minimum of an array?

    in Introduction to Java

    A. Introduction

    Now that your array is filled with random height data. How to find average height? Maximum or minimum height?

    B. Watch ... (Slides)

    C. Now, open your code in 6.2, complete:

    1. Print out the average height

    2. Print out the maximum and minimum height

    3. You can try R7.9 too...

    D. Check how well you can score, and see if you can find out what are wrong in these slides.

    1 comment
    0
    mr.ricklu
    Aug 26, 2018

    import java.util.Scanner;

    class MaxMin {

    public static void main(String[] args) {

    Scanner Oscar = new Scanner(System.in);

    System.out.println("Please enter the number of elements you will have in the array");

    int numberof = Oscar.nextInt();

    double[] MiniMax = new double[numberof];

    for(int i=1; i<=numberof; i++){

    System.out.println("Please enter one element of the array");

    MiniMax[i-1] = Oscar.nextDouble();

    }

    double Max = MiniMax[0];

    for(int i=1; i<=numberof-1; i++){

    if(MiniMax[i]>Max){

    Max = MiniMax[i];

    }

    }

    System.out.println("The greatest number in that array is " + Max);

    double Min = MiniMax[0];

    for(int i=1; i<=numberof-1; i++){

    if(MiniMax[i]<Min){

    Min = MiniMax[i];

    }

    }

    System.out.println("The smallest number in that array is " + Min);

    }

    }


    0
    1 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners