CS 113 - Computer Science 1

Lab 4

Arrays and yet more Unix

In this lab you will:
  1. Learn two more Unix commands
  2. Write two Java programs using for or whileloops

Unix

Often you are in a terminal window and have just entered a directory, and having used the ls command to see its contents, you wonder "what is in that file?" You could, of course, open it in VSC, but that is a pain since you are already in the terminal. Unix to the rescue. There are two commands you can use.
CommandExplanation
catPrints the entire file to the screen. This is mostly useful for short files
lessPrints the file to the screen, one "page" at a time where are page is the amount of stuff that will fit onto your terminal window.
To advance to the next page, hit the spacebar.
To go back a page, hit 'b'.
To quit, hit 'q'

Java

Arrays, part 1

Write a program called Verifier that goes through each command line input and verifies that that input is an integer in the range 0--100. If the input is not an integer, the program may die. If the input is an integer, but not in the right range, the program should print an error message -- e.g.
    -42 is not in the range 0 .. 100
The program should go through all command line inputs, be there 2 or 200. If all inputs are integers in the correct range, the program should print
    The input is good

Arrays, part 2

Write a program called Reverse that takes integers from the command line. First, create an integer array called forward that has the same length as the the number of command line inputs. Next convert the command line inputs into integers, storing the result in "forward".

Next, create an array of doubles of the same size as "forward", but named "reversed". Then fill "reversed" square root of the the contents of "forward" but in reverse order. Do this using a loop. Finally, print the contents of reversed and forward using a "for" loop so the zeroth entry in "forward" and "reversed" appear on the same line, followed by the first, ...

java Reverse 2 4 8 12 42
geoffreytowell@Geoff2020Mac Lab04 % java ReverseCI 2 4 8 17 42 169
0: 2  13.0
1: 4  6.48074069840786
2: 8  4.123105625617661
3: 17  2.8284271247461903
4: 42  2.0

What to hand in

Use your phone to take a picture of VSC screen(s) with your java programs. Send the picture to gtowell@brynmawr.edu