CISC 1115
Introduction to Programming Using Java
Lab #11
Arrays

How to Develop and Submit your Labs

Lab 11.1 — Array Basics (ArrayBasics) (Approval)

Prompt the user for an integer value, create an integer array of that size, populate it (ising a for loop) with the values 1 … size, and print out the elements of the array preceded by their indices.

Sample Test Run

How large an array? 5
0: 1
1: 2
2: 3
3: 4
4: 5

Lab 11.2 — Array Input (ArrayInput)

The file text.text contains a header value, followed by that many lines of text. Create an array of strings of the appropriate size, read in the lines of text into the array — one line of text per element, and print out the elements of the array in reverse each element preceded by it subscript. Don't forget to use nextLine so that an entire line is read in — that will also permit blanks in the text.

Sample Test Run

For example if the file text.text contains:

4
Arrays allow the programmer to create collection of objects
The size of an array can be obtained in Java using the .length field
For loops are the loop of choice for processing an array
The first element of an array has an index of 0
the program should produce the following output:
3. The first element of an array has an index of 0
2. For loops are the loop of choice for processing an array
1. The size of an array can be obtained in Java using the .length field
0. Arrays allow the programmer to create collection of objects
Note:There is a bit of an issue involved in reading in the above file (and in general, mixing nextLine calls with the other nextXXX calls). You can read about it in section 3.10 'The Scanner Bug' of the text; here is an overview, and the way to handle it: