CSE 1223 Intro to Computer Programming in Java
Midterm II Practice Guide 2025-2026
1. Declaring an array double [] temperature;
int [] scores;
boolean [] answers;
String [] names;
2. Allocating an array temperatures = new double [10];
scores = new int [20];
answers = new boolean [5];
names = new String [15];
3. Accessing array ele- temperatures [2];
ments
4. how do you find the temperatures.length;
number of elements in
an array
5. Declare and allocate an int [] a = new int [10];
array of 10 integers and
call it a
6. Write a loop that initial- int [] a = new int [10];
izes the 10 elements of for (int i = 1; i < a.length; i++){
the array to the integers a[i] = i+1;
1, 2, 3, 4, 5, 6, 7, 8, 9, }
10
7. Write a loop that outputs for (int k = 0; k < a.length; k++){
the elements of the System.out.println(a[(a.length-1)-k]);
array, one per line, in re- }
verse order
the last element is a[(a.length - 1)]
1/9
, CSE 1223 Intro to Computer Programming in Java
Midterm II Practice Guide 2025-2026
length is 10
last element index is 9
8. Write a program private static void printRectangle (int w, int h){
segment—using for for (int i = 0; i<h; i++){
loops— for (int j = 0; j<w; j++){
that given two integer System.out.print('+');
variables, width and }
height, outputs a rectan- System.out.println();
gle of '+'s of the given }
width and height. }
9. Arrays in java are objects
10. Arrays hold a reference to an array object
11. Declaring an array list ArrayList<String> stringList = new ArrayList<String>();
12. We want code that reads import java.util.ArrayList;
in text one line at a time ...
until the user enters the public static void main(String [] args) {
word "stop" ArrayList<String> stringList = new ArrayList<String>();
Then the code should re- Scanner keyboard = new Scanner(System.in);
peat back all of the lines String input = "";
in reverse order while (!input.equals("stop")) {
We do not know how input = keyboard.nextLine();
many lines of text there stringList.add(input);
will }
be before we start int i = stringList.size()-1;
while (i>0) {
System.out.println(stringList.get(i));
i = i - 1;
2/9
Midterm II Practice Guide 2025-2026
1. Declaring an array double [] temperature;
int [] scores;
boolean [] answers;
String [] names;
2. Allocating an array temperatures = new double [10];
scores = new int [20];
answers = new boolean [5];
names = new String [15];
3. Accessing array ele- temperatures [2];
ments
4. how do you find the temperatures.length;
number of elements in
an array
5. Declare and allocate an int [] a = new int [10];
array of 10 integers and
call it a
6. Write a loop that initial- int [] a = new int [10];
izes the 10 elements of for (int i = 1; i < a.length; i++){
the array to the integers a[i] = i+1;
1, 2, 3, 4, 5, 6, 7, 8, 9, }
10
7. Write a loop that outputs for (int k = 0; k < a.length; k++){
the elements of the System.out.println(a[(a.length-1)-k]);
array, one per line, in re- }
verse order
the last element is a[(a.length - 1)]
1/9
, CSE 1223 Intro to Computer Programming in Java
Midterm II Practice Guide 2025-2026
length is 10
last element index is 9
8. Write a program private static void printRectangle (int w, int h){
segment—using for for (int i = 0; i<h; i++){
loops— for (int j = 0; j<w; j++){
that given two integer System.out.print('+');
variables, width and }
height, outputs a rectan- System.out.println();
gle of '+'s of the given }
width and height. }
9. Arrays in java are objects
10. Arrays hold a reference to an array object
11. Declaring an array list ArrayList<String> stringList = new ArrayList<String>();
12. We want code that reads import java.util.ArrayList;
in text one line at a time ...
until the user enters the public static void main(String [] args) {
word "stop" ArrayList<String> stringList = new ArrayList<String>();
Then the code should re- Scanner keyboard = new Scanner(System.in);
peat back all of the lines String input = "";
in reverse order while (!input.equals("stop")) {
We do not know how input = keyboard.nextLine();
many lines of text there stringList.add(input);
will }
be before we start int i = stringList.size()-1;
while (i>0) {
System.out.println(stringList.get(i));
i = i - 1;
2/9