Site Search

CS 111: Lab 1 main content

Student Learning Objectives

Demonstrate the ability to

Lab 1 Assignment

Sample Session

  How many numbers would you like to enter? 3

  Please enter the 3 values:
  5.6
  4.5
  8.22

  The values you entered were
  5.6
  4.5
  8.22

  Their sum is 18.32
  Their average is 6.1066666666666665

To Receive Credit

Programming Challenge

If you finish early, get yourself checked off first!

Re-save your program as HardArray.java, modify your program to prompt the user for the name of the input file and the number of values to read in from the file. Read in these values, display them, and then calculate and display their total and their average.

Section 5.10 beginning on page 311 of your textbook explains how to read in input from a file. Your HardArray.java program will still need to read in the size of the array from the keyboard.

Sample session: Programming Challenge (optional, not required)

  Please enter the name of the input file: numbers.txt
  How many numbers to read in? 5

  The values read in were
  1.122
  2.21
  3.3
  4.456
  5.5555

  Their sum is 16.643500000000003
  Their average is 3.3287000000000004