ICS 211 Homework 1
Java Review and Recursion
Part 1: Java Review
Write a Java application that:
- declares a
Scanner variable
- declares an array of 26 String values, and initializes
each array element with the corresponding lowercase letter of the alphabet
- prompts the user to enter an integer and uses the
Scanner's nextInt method to obtain that integer from
the user
- prints out the corresponding letter from the array (next part
only added after the assignments were turned in: ), so if the input is
zero, should print "a", and should print "z" for an input of 25.
- creates a new array of size 27, puts a string containing a space
(" ") at index 0 in the new array, and copies all the other
letters to positions 1..26 of the new array. The simplest way to do
this is to use System.arraycopy()
- loops through the array, printing each entry, either as is, or
uppercase if it is a vowel ("a", "e", "i",
"o", "u").
- prints the number of non-vowel strings at the end of the loop.
Requirements
- The program must catch the InputMismatchException from the call
to nextInt, in which case the program must display an
appropriate error message and end the program.
- The loop should work for any size initial array, and should not
depend on the array size -- you may use array.length to find
out the size of the array.
- You should memorize the sequence of parameters to
System.arraycopy() and their meaning. This will be useful
later in the semester (and may appear on quizzes or exams).
Part 2: Recursion
Write a Java application that executes 4 methods, 2 iterative and
2 recursive.
Your program must accept an integer Q on the command line. This
integer is the input for all 4 methods. If the command line has
anything other than a single integer, your program should print
an error message and exit.
If the integer Q is negative or zero, your program should exit
without printing anything.
Otherwise, execute each of the following four methods:
- Method 1: use a loop to print a row of Q asterisks
- Method 2: use recursion to print a row of Q asterisks
- Method 3: use a loop to print the numbers Q, Q - 1, ... 3, 2, 1
- Method 4: use recursion to print the numbers Q, Q - 1, ... 3, 2, 1
Turning in the Assignment
Email your assignment to the TA following the instructions
posted here.
Since this assignment requires you to turn in two classes, they
should be named named LastNameFirstNameXY.java, where X is the
assignment number and Y is the part number. So for example, for this
assignment I would send in BiagioniEdoardo11.java and
BiagioniEdoardo12.java.
Grading
The two parts of the assignment are each graded on a scale of 0..100,
using the TA's grading guidelines as if they were independent
assignments. The two grades are then combined into one by adding them
together and dividing the result by two.