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
    Jun 29, 2019
      ·  Edited: Jun 07, 2021

    6.1 How to store 300 values in your program?

    in Introduction to Java

    A. Introduction

    Suppose you are in a large high school and there are 300 students in your class. Even though each of you know your own height, the school administration wants to know the average height of this class and the tallest student.


    Similarly, sometimes you might want to find out the average price of all 5-seat SUVs, as well as the most expensive or inexpensive one etc.


    This type of problems involves handling a relatively large amount of values in your program. You can not create individual variables to store them. What to do?


    B. Watch how to create an array ... ( Slides )




    C. Now, please try the following in your IDE and save your project for the following sessions.

    1. Create a double array of 10-30 elements, name it height.

    2. Is there another way to declare an array? If you print out height[0], what value will be printed? what value is height[2] or height[299]? height[300] ? Try to print all of these and explain why you get what you see.

    D. Program

    1. Declare, create and initialize an int, a double, and a String array, each with 10-30 elements.

    2. Find the sum of the int array.

    3. Find the average of the double array.

    4. Does your String array contains the word "Hello"? Write code to find out.

    5. How do you find the maximum and/or minimum value of the int or double array?

    6. Can you create an array with varied length?

    7. How do you copy an array?

    0 comments
    0
    0 comments

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

    • lol-101dotcom

    ©2020 Legion of Learners