COSC 101 - Final Exam Study (Fall 2022)
The following print statement does not print a newline after the output. System.out.format("%d", 10); Change what is in parentheses to print a newline after 10. There is more than one way to do this, and Canvas will count each way as correct. System.out.format(________);
"%d\n", 10
What will be printed to the screen after the following code executes? int x, y; x = -3; y = 5; y *= x++ + ++y; System.out.println(x + " " + y);
-2 15
public static void main(String[] args) { double data = 1.25512; String out = String.format("%.2f", data); System.out.print(out); } What is printed to the screen in the code above?
1.26
What is printed to the screen given the code below? public static void main(String[] args) { double v = 10.751; System.out.print((int)v); }
10
public static void main(String[] args) { int val = 100; System.out.print(val++); } What is printed to the screen given the code above?
100
public static void main(String[] args) { int a = 1; int b = 2; int c = 5; int out = 100 * a + b * 10 + (c * (int)1.5); System.out.print(out); } What is printed given the code above?
125
What is printed to the screen given the code below? public static void main(String[] args) { int i = 1345; int j = 0; while (i > 0) { i -= 1; j += 1; } System.out.print(j); }
1345
public static void main(String[] args) { double val = 13 / 5; System.out.print(val); } What is printed to the screen given the code above?
2.0
public static void main(String[] args) { double val = 5 / (4 * 0.5); System.out.print(val); } What is printed to the screen in the code above?
2.5
public static void main(String[] args) { int a = 13; int b = 10; System.out.print(a % b); } What is printed given the code above?
3
public static void main(String[] args) { int a = 100; double b = 3.5; System.out.print(a * (int)b); } What is printed to the screen given the code above?
300
class test { public static void main(String[] args) { double income; double tax; Scanner scan = new Scanner(System.in); System.out.print("Enter your income: "); income = scan.nextDouble(); if (income > 3000.0) { tax = 0.05 * income; } else if (income > 5000.0) { tax = 0.10 * income; } else if (income > 10000.0) { tax = 0.20 * income; } System.out.print((int)tax); } } What is printed to the screen given the code above if the user enters 10000?
500
What is printed to the screen given the code below? public static void main(String[] args) { int i = 52472; int j = 0; do { j += 1; } while (i < 0); System.out.print(i); }
52472
What is printed to the screen given the code below? public static void main(String[] args) { int i; for (i = 52; i < 705; i++) { } System.out.print(i); }
705
What is printed to the screen given the code below? public static void main(String[] args) { int j = 0; int i; for (i = 123; i < 937; i++) { j += 1; } System.out.print(j); }
814
What is printed to the screen given the code below? public static void main(String[] args) { int i = 940; int j = 0; do { i -= 1; j += 1; } while (i > 0); System.out.print(j); }
840
class test { public static void main(String[] args) { int i; int max = 1000; int j = 0; for (i = 10;i < max;i++) { j += 1; } System.out.print(j); } } What is printed to the screen given the code above?
990
public static void main(String[] args) { int i = 7; int j = 2; int k = 5; if (i > j) { System.out.print("A"); } else if (i > k) { System.out.print("B"); } else if (k > j) { System.out.print("C"); } else { System.out.print("D"); } } What is printed to the screen given the code above?
A
public static void main(String[] args) { int i = 7; int j = 2; int k = 5; if (i > j) { System.out.print("A"); } if (i > k) { System.out.print("B"); } if (k > j) { System.out.print("C"); } if (j == k) { System.out.print("D"); } } What is printed to the screen given the code above?
ABC
switch (data) { case 1: System.out.print("A"); case 2: System.out.print("B"); case 3: System.out.print("C"); break; case 4: System.out.print("D"); default: System.out.print("E"); break; } What is printed to the screen given the code above if the variable data equals 2?
BC
What does the following code print? int x = -5; while (x < 0) { x++; System.out.print(x + " "); } [] -4 -3 -2 -1 [] 5 4 3 2 1 0 [] -5 -4 -3 -2 -1 0 [] 4 3 2 1 [] 5 4 3 2 1 [] -4 -3 -2 -1 0 [] -5 -4 -3 -2 -1 [] 4 3 2 1 0
[] -4 -3 -2 -1 [] 5 4 3 2 1 0 [] -5 -4 -3 -2 -1 0 [] 4 3 2 1 [] 5 4 3 2 1 ∎ -4 -3 -2 -1 0 [] -5 -4 -3 -2 -1 [] 4 3 2 1 0
How many times does the following method print a *? for (int i = 1; i < 5; i++) { System.out.print("*"); } [] 0 [] 1 [] 6 [] 4 [] 5
[] 0 [] 1 [] 6 ∎ 4 [] 5
What is printed as a result of the following code segment? for (int k = 0; k < 20; k+=2) { if (k % 3 == 1) { System.out.print(k + " "); } } [] 0 2 4 6 8 10 12 14 16 18 [] 4 10 16 [] 4 16 [] 0 6 12 18 [] 1 4 7 10 13 16 19
[] 0 2 4 6 8 10 12 14 16 18 ∎ 4 10 16 [] 4 16 [] 0 6 12 18 [] 1 4 7 10 13 16 19
Consider the following code segment: int x = 10; int y = 2; int count = 1; while(x > y) { x /= y; count++; } What will the value of count be after executing the code segment? [] 1 [] 2 [] 4 [] 3 [] 10
[] 1 [] 2 [] 4 ∎ 3 [] 10
How many stars are printed when the following code is executed? for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { System.out.println("*"); } } [] 10 [] It is an infinite loop [] 50 [] 0 [] 5 [] 15 [] 25
[] 10 [] It is an infinite loop [] 50 [] 0 [] 5 [] 15 ∎ 25
Given the BankAccount class definition below, what is the output of the code in the main method? public class BankAccount { private int accountID; private double total; public BankAccount(int id, double initialDeposit) { accountID = id; total = initialDeposit; } public void deposit(double money) { total = total + money; } public void withdraw(double money) { total = total - money; } public void printCurrentTotal() { System.out.print(total); } public static void main(String[] args) { BankAccount newAccount = new BankAccount(12345, 100.00); newAccount.withdraw(30.00); newAccount.deposit(40.00); newAccount.printCurrentTotal(); } } [] 100.00 [] 10.00 [] 110.00 [] 90.00
[] 100.00 [] 10.00 ∎ 110.00 [] 90.00
What value will be printed in the console after this series of commands? Assume that the ArrayList package has been imported. ArrayList<Integer> array = new ArrayList<Integer>(); array.add(3); array.add(9); array.add(10); array.remove(1); array.set(0, 3); int num = array.get(1); System.out.println(num); [] 2 [] 10 [] 9 [] 3
[] 2 ∎ 10 [] 9 [] 3
What will the following code segment output? String[ ] grades = {"A","C","B","A","B", "A"}; int mystery = 0; for (int i = 0; i < grades.length; i++) { if (grades[i].equals("A")) { mystery ++; } } System.out.println(mystery); [] 2 [] 3 [] 0 [] 1 [] null
[] 2 ∎ 3 [] 0 [] 1 [] null
Given the following, what will be printed out? int a = 2; int b = 3; int c = 4; System.out.println(a * b + b / a + (a * c / 4.0) * c); [] 24.0 [] 15.0 [] 15 [] 24
[] 24.0 ∎ 15.0 [] 15 [] 24
What will be printed after the following code executes? double d; { d = 24; int e = 6; } System.out.print(d + e + " " + d/6); [] 24.0 6 4.0 [] 30.0 4.0 [] 24 6 4.0 [] 24 6 4 [] The code will not execute because of a compilation error
[] 24.0 6 4.0 [] 30.0 4.0 [] 24 6 4.0 [] 24 6 4 ∎ The code will not execute because of a compilation error
What does the following code print? for (int i = 3; i <= 12; i++) { System.out.print(i + " "); } [] 3 5 7 9 11 [] 3 4 5 6 7 8 9 10 11 12 [] 5 6 7 8 9 [] 4 5 6 7 8 9 10 11 12
[] 3 5 7 9 11 ∎ 3 4 5 6 7 8 9 10 11 12 [] 5 6 7 8 9 [] 4 5 6 7 8 9 10 11 12
Consider the following code segment: int b = 10; String result = ""; while(b < 100) { result += b; b *= 2; } System.out.println(result); What, if anything, is printed as a result of executing this statement? [] 310 [] 150 [] 10204080160 [] 10204080 [] There will not be any result printed, as ints cannot be converted to type String.
[] 310 [] 150 [] 10204080160 ∎ 10204080 [] There will not be any result printed, as ints cannot be converted to type String.
What is the value of len after the following executes? String s1 = "Hey, buddy!"; int len = s1.length(); [] 8 [] 12 [] 11 [] 10
[] 8 [] 12 ∎ 11 [] 10
Which of the following Boolean operators tests for not equals? [] <= [] >= [] = [] == [] != [] > [] <
[] <= [] >= [] = [] == ∎ != [] > [] <
Which of the following Boolean operators tests for equality? [] = [] != [] >= [] <= [] == [] < [] <
[] = [] != [] >= [] <= ∎ == [] < [] <
A student has created a Cat class. The class contains variables to represent the following. - A String variable called color to represent the color of the cat - A String variable called breed to represent the breed of the cat - An int variable called age to represent the age of the cat The object myCat will be declared as type Cat. Which of the following descriptions is accurate? [] An attribute of Cat is myCat. [] color, breed, and age are instances of the Cat class. [] Cat is an instance of the myCat class. [] An attribute of breed is String. [] age is an attribute of the myCat object.
[] An attribute of Cat is myCat. [] color, breed, and age are instances of the Cat class. [] Cat is an instance of the myCat class. [] An attribute of breed is String. ∎ age is an attribute of the myCat object.
Consider the following code segment. for(int j = 0; j < 4; j++) //line 1 { for(int k = 0; k < j+1; k++) { System.out.print(k + ""); } } Which of the following best explains the result of changing j < 4 to j > 4 on line 1? [] An infinite loop will occur because the termination of the loop will never be reached. [] No output will be produced, as the boolean condition will never be met in the outer for loop. [] The numbers will be printed in reverse order compared to the original because the outer loop will occur in reverse order. [] The program will produce the same result, as the number of iterations in the outer loop hasn't changed.
[] An infinite loop will occur because the termination of the loop will never be reached. ∎ No output will be produced, as the boolean condition will never be met in the outer for loop. [] The numbers will be printed in reverse order compared to the original because the outer loop will occur in reverse order. [] The program will produce the same result, as the number of iterations in the outer loop hasn't changed.
Which of the following data types is required when the specifier %f is used? [] ArrayList [] array [] list [] double [] String [] boolean [] int
[] ArrayList [] array [] list ∎ double [] String [] boolean [] int
Assume that SomeClass and MainClass are properly defined in separate files. What is the output of the code in main()? class SomeClass { public SomeClass() { System.out.print("Hello "); } void printSomething(String name) { System.out.print("Hello " + name + " "); } } public class MainClass { public static void main(String[] args) { SomeClass someClass = new SomeClass(); someClass.printSomething("Bob"); } } [] Bob [] Hello Bob [] Hello Bob Hello Bob [] Hello Bob Hello [] Hello Hello Bob
[] Bob [] Hello Bob [] Hello Bob Hello Bob [] Hello Bob Hello ∎ Hello Hello Bob
There is a method called checkString that determines whether a string is the same forwards and backwards. The following data set inputs can be used for testing the method. What advantage does Data Set 2 have over Data Set 1? Data Set 1 Data Set 2 aba bcb abba bcd aBa [] Data Set 2 contains fewer values than Data Set 1 [] Data Set 2 contains one string which should return true and one that should return false. [] All strings in Data Set 2 have the same number of characters. [] The strings in Data Set 2 are all lowercase [] There are no advantages
[] Data Set 2 contains fewer values than Data Set 1 ∎ Data Set 2 contains one string which should return true and one that should return false. [] All strings in Data Set 2 have the same number of characters. [] The strings in Data Set 2 are all lowercase [] There are no advantages
The following function computes the hypotenuse of a right triangle. public double findHypotenuse(int side1, int side2){ double hyp = Math.sqrt(side1 * side1 + side2 * side2); return hyp; } The following code found in main throws an error. What is the bug? int side1 = 3; int side2 = 4; findHypotenuse(side1, side2); System.out.println(hyp); [] Formal parameters and actual arguments cannot have the same name. [] That's a lie. The code works just fine and there is no bug. [] hyp is a local variable. It can only be accessed in findHypotenuse. [] hyp has to be accessed by using findHypotenuse.hyp
[] Formal parameters and actual arguments cannot have the same name. [] That's a lie. The code works just fine and there is no bug. ∎ hyp is a local variable. It can only be accessed in findHypotenuse. [] hyp has to be accessed by using findHypotenuse.hyp
Which of the following would equal 2? I. int x = 0; x ++; x += x; II. int y = 4; y ++; y /= 2; III. int z = 4; z += 2; z /= 2; [] I only [] II only [] III only [] I, II, and III [] I and II only
[] I only [] II only [] III only [] I, II, and III ∎ I and II only
Consider the Party class below. public class Party { private int numOfPeople; //number of people at the party private int capacity; //total capacity of people at party public Party(int people, int cap) { numOfPeople = people; capacity = cap; } public boolean updateNumOfPeople(int additionalPeople) { /* missing code */ } } The class contains the updateNumOfPeople method, which is intended to update the instance variable numOfPeople under certain conditions and return a value indicating whether the update was successful. If adding additionalPeople to the current number of people would lead to the number going over the capacity, then the update would be unsuccessful. Otherwise, if adding the number of additional people is still below or at the capacity, the update is successful. Which of the following code segments can replace missing code to ensure that the updateNumOfPeople method works as intended? I. if (numOfPeople + additionalPeople > capacity) { return false; } else { numOfPeople += additionalPeople; return true; } II. if (numOfPeople + additionalPeople <= capacity) { numOfPeople += additionalPeople; return true; } else { return false; } III. if (numOfPeople += additionalPeople <= capacity) { return true; } else { return false; } [] I, II, and III [] III only [] II only [] I only [] I and II only
[] I, II, and III [] III only [] II only [] I only ∎ I and II only
In order to ride the zip line, you need to be at least 12 years old and weigh at least 75 pounds, but no more than 300 pounds. Which of the following code segments would correctly determine if you can ride the zip line? I. if (age >= 12 && 75 <= weight <= 300) { return true; } return false; II. if (age >= 12) { if (weight >= 75 && weight <= 300) { return true; } } return false; III. if (age >= 12 && (weight >= 75 || weight <= 300)) { return true; } return false; [] III only [] I only [] I and II only [] I, II, and III [] II only
[] III only [] I only ∎ I and II only [] I, II, and III [] II only
Consider the following class: public class Insect { private String name; private int numLegs; private boolean hasWings; private boolean hasExoskeleton; public Insect(String theName, int legNumber, boolean isWinged, boolean isExoskeleton) { name = theName; numLegs = legNumber; hasWings = isWinged; hasExoskeleton = isExoskeleton; } public Insect(String theName, int legNumber, boolean isWinged) { name = theName; numLegs = legNumber; hasWings = isWinged; hasExoskeleton = true; } } Which of the following is NOT a possible header for a new constructor for the Insect class? [] Insect(String theName, int legNumber) [] Insect() [] Insect(String theName, int legNumber, boolean isExoskeleton) [] Insect(String theName)
[] Insect(String theName, int legNumber) [] Insect() ∎ Insect(String theName, int legNumber, boolean isExoskeleton) [] Insect(String theName)
What is true of a void method? [] It takes no parameters. [] It returns any value. [] It can take any parameter. [] It returns no value.
[] It takes no parameters. [] It returns any value. [] It can take any parameter. ∎ It returns no value.
The following method is a search method intended to return the index at which a String value occurs within an ArrayList: public int search(ArrayList<String> list, String target) //Line 1 { int counter = 0; while(counter < list.size()) //Line 4 { if(list.get(counter).equals(target)) { return list.get(counter); //Line 8 } counter++; //Line 10 } return -1; //Line 12 } However, there is currently an error preventing the method to work as intended. Which of the following Lines needs to be modified in order for the method to work as intended? [] Line 10 - As written, the counter will skip every other value. [] Line 4 - The loop should go to < list.size() - 1 so as to avoid an IndexOutofBoundsException. [] Line 8 - The return should be the counter, not list.get(counter). [] Line 12 - The return value should be a String, not an int. [] Line 1 - The method should be returning a String value, not an int.
[] Line 10 - As written, the counter will skip every other value. [] Line 4 - The loop should go to < list.size() - 1 so as to avoid an IndexOutofBoundsException. ∎ Line 8 - The return should be the counter, not list.get(counter). [] Line 12 - The return value should be a String, not an int. [] Line 1 - The method should be returning a String value, not an int.
What will the following code output when executed? String word = "elementary"; if (word.length() > 8) { System.out.println("Long Word"); } if (word.length() > 5) { System.out.println("Medium Word"); } else if (word.length() > 0) { System.out.println("Short Word"); } else { System.out.println("No Word"); } [] Long Word Medium Word Short Word [] Long Word Medium Word Short Word No Word [] Long Word [] Long Word Medium Word [] No Word
[] Long Word Medium Word Short Word [] Long Word Medium Word Short Word No Word [] Long Word ∎ Long Word Medium Word [] No Word
Given the code snippet, public class Pokemon { private String name; private int health; public Pokemon(String name, int health) { name = name; health = health; } } what is wrong with the class definition? Hint: We expect the instance variables name and health to be initialized in the constructor. [] Missing void in constructor definition [] Must use this in constructor when the constructor parameters have the same name as instance variables. ie: this.name = name; this.health = health; [] Class constructors must be private [] The constructor parameters cannot have the same names as the instance variables.
[] Missing void in constructor definition ∎ Must use this in constructor when the constructor parameters have the same name as instance variables. ie: this.name = name; this.health = health; [] Class constructors must be private [] The constructor parameters cannot have the same names as the instance variables.
Consider the following class. Which of the following code segments would successfully create a new Movie object? public class Movie { private String title; private String director; private double rating; private boolean inTheaters; public Movie(String t, String d, double r) { title = t; director = d; rating = r; inTheaters = false; } public Movie(String t) { title = t; director = "unknown"; rating = 0.0; inTheaters = false; } } [] Movie four = new Movie("My Cool Movie", "Steven Spielburg", "4.4"); [] Movie one = new Movie("Harry Potter", "Bob"); [] Movie two = new Movie("Sponge Bob"); [] Movie three = new Movie(title, rating, director); [] Movie five = new Movie(t);
[] Movie four = new Movie("My Cool Movie", "Steven Spielburg", "4.4"); [] Movie one = new Movie("Harry Potter", "Bob"); ∎ Movie two = new Movie("Sponge Bob"); [] Movie three = new Movie(title, rating, director); [] Movie five = new Movie(t);
A student has created a Movie class. The class contains variables to represent the following. - A String variable called title to represent the title of the movie - A String variable called director to represent the director of the movie - A double variable called rating to represent the rating of the movie The object scaryMovie will be declared as type Movie. Which of the following descriptions is accurate? [] Movie is an instance of scaryMovie. [] scaryMovie is an instance of the Movie class. [] Title, director, and rating are instances of the scaryMovie object. [] An attribute of the scaryMovie class is title. [] An attribute of the Movie instance is scaryMovie
[] Movie is an instance of scaryMovie. ∎ scaryMovie is an instance of the Movie class. [] Title, director, and rating are instances of the scaryMovie object. [] An attribute of the scaryMovie class is title. [] An attribute of the Movie instance is scaryMovie
public class ScopeQuiz { private int count = 0; public void printPointSums() { int sum = 0; // POINT A for(int i = 0; i < 10; i++) { sum += i; } int result = sum + count; } } Which variables are in scope at the point labeled // POINT A? In other words, which variables exist at that point in the code? [] Only sum [] sum, count, i, and result [] sum and result [] sum and count [] sum, count, and i
[] Only sum [] sum, count, i, and result [] sum and result ∎ sum and count [] sum, count, and i
Consider the definition of the Party class below. The class uses the instance variable numOfPeople to indicate how many people are at the party. public class Party { private int numOfPeople; private String partyHost; public Party (String name, int people) { partyHost = name; numOfPeople = people; } } Which of the following statements will create a Party object that represents a party that has 3 people in it? [] Party p = new Party("Kelly", "three"); [] Party p = new Party("Elizabeth", three); [] Party p = new Party("Katie", "2 + 1"); [] Party p = new Party("Sharon", "3"); [] Party p = new Party("Lindsay", 3);
[] Party p = new Party("Kelly", "three"); [] Party p = new Party("Elizabeth", three); [] Party p = new Party("Katie", "2 + 1"); [] Party p = new Party("Sharon", "3"); ∎ Party p = new Party("Lindsay", 3);
Consider the following class definition. public class Liquid { private int currentTemp; private int boilingPoint; public Liquid(int ct, int bp) { currentTemp = ct; boilingPoint = bp; } public void changeTemp(int newTemp) { currentTemp = newTemp; } public void increaseTemp(int howMuch) { currentTemp = newTemp + howMuch; } } Which of the following best explains why the class will not compile? [] The Liquid constructor needs a return type. [] The instance variables currentTemp and boilingPoint should be public instead of private. [] The class is missing an accessor method. [] The Liquid class is missing a constructor. [] The variable newTemp is not defined in the increaseTemp method.
[] The Liquid constructor needs a return type. [] The instance variables currentTemp and boilingPoint should be public instead of private. [] The class is missing an accessor method. [] The Liquid class is missing a constructor. ∎ The variable newTemp is not defined in the increaseTemp method.
Given the following code: public class TvShow { private String name; private int channel; public TvShow (String name, int channel) { this.name = name; this.channel = channel; } public void getName() { return name; } public void setName(String name) { this.name = name; } } Which of the following explains why this code will not compile? [] The constructor is missing a return type and it should be set to boolean. [] The return type for the setName method should be set to String. [] The constructor is missing a return type and it should be set to void. [] The instance variables name and channel should be public. [] The return type for the getName method should be set to String.
[] The constructor is missing a return type and it should be set to boolean. [] The return type for the setName method should be set to String. [] The constructor is missing a return type and it should be set to void. [] The instance variables name and channel should be public. ∎ The return type for the getName method should be set to String.
Consider the following Cat class, with the cat's age stored in the age attribute. The getAge method is intended to allow methods in other classes to access a Cat object's age value; however, it does not work as intended. Which of the following best explains why the getAge method does NOT work as intended? public class Cat { private int age; public Cat(int a) { age = a; } public int getAge() { return a; } } [] The return type of the getAge method should be void. [] The getAge method should be declared private. [] The variable age is not declared inside the getAge method. [] The instance variable age should be returned instead of a, as a is local to the constructor. [] The getAge method should have at least one parameter.
[] The return type of the getAge method should be void. [] The getAge method should be declared private. [] The variable age is not declared inside the getAge method. ∎ The instance variable age should be returned instead of a, as a is local to the constructor. [] The getAge method should have at least one parameter.
What are parameters? [] The type that is given to a variable. [] The formal names given to the data that gets passed into a method. [] The value that a method returns. [] The formal values that a method prints to the screen.
[] The type that is given to a variable. ∎ The formal names given to the data that gets passed into a method. [] The value that a method returns. [] The formal values that a method prints to the screen.
If I have a Scanner declared as myScanner, myScanner.next() will read an entire line of input and save it as a string. [] True [] False
[] True ∎ False
True or False: Linear Search becomes more efficient as more values are added to a particular data set. [] True [] False
[] True ∎ False
What is the value of the variable val given the code below? public static void main(String[] args) { int a = 123; int b = 764; int c = 123; boolean val = (a == b) || (a != c); } [] True [] False
[] True ∎ False
What is printed as a result of executing the following code segment? ArrayList<Integer> list1 = new ArrayList<Integer>(); list1.add(new Integer(1)); list1.add(new Integer(2)); list1.add(new Integer(3)); list1.set(2, new Integer(4)); list1.add(2, new Integer(5)); list1.add(new Integer(6)); System.out.println(list1); [] [ 1, 2, 3, 4, 5] [] [ 1, 2, 5, 4, 6] [] [ 1, 2, 4, 5, 6] [] [ 1, 5, 2, 4, 6]
[] [ 1, 2, 3, 4, 5] ∎ [ 1, 2, 5, 4, 6] [] [ 1, 2, 4, 5, 6] [] [ 1, 5, 2, 4, 6]
Given the list nums = [4, 2, 3, 4, 5] what is the result after executing nums.remove(4)? [] [4, 2, 3, 5] [] [2, 3, 5] [] [4, 2, 3, 4] [] [2, 3, 4, 5]
[] [4, 2, 3, 5] [] [2, 3, 5] ∎ [4, 2, 3, 4] [] [2, 3, 4, 5]
What is in the list nums if it initially contained {5, 3, 1} and the following code is executed? nums.add(6); nums.add(0,4); nums.remove(1); [] [4, 3, 6] [] [4, 3, 1, 6] [] [4, 5, 3, 6] [] [5, 3, 6] [] [5, 3, 1, 6]
[] [4, 3, 6] ∎ [4, 3, 1, 6] [] [4, 5, 3, 6] [] [5, 3, 6] [] [5, 3, 1, 6]
What is printed as a result of executing the following code segment? ArrayList<String> list1 = new ArrayList<String>(); list1.add("a"); list1.add("b"); list1.add(0,"c"); list1.set(1, "d"); list1.set(0, "e"); list1.add("b"); System.out.println(list1); [] [e, d, b] [] [e, d, a, b, b] [] [e, d, a, b] [] [e, d, b, b]
[] [e, d, b] [] [e, d, a, b, b] [] [e, d, a, b] ∎ [e, d, b, b]
Given the following code segment, what is the value of num when it finishes executing? double value = Math.random(); int num = (int) (value * 5) + 5; [] a random number from 1 to 5 (inclusive) [] a random number from 0 to 4 (inclusive) [] a random number from 5 to 9 (inclusive) [] a random number from 5 to 10 (inclusive)
[] a random number from 1 to 5 (inclusive) [] a random number from 0 to 4 (inclusive) ∎ a random number from 5 to 9 (inclusive) [] a random number from 5 to 10 (inclusive)
The value that a non-void method outputs is called [] an argument. [] a return value. [] a print statement. [] a parameter.
[] an argument. ∎ a return value. [] a print statement. [] a parameter.
Given an instance of the Athlete class called athlete, what is the proper way to set the value of the jersey number after it has been instantiated? public class Athlete { private String first_name; private String last_name; private int jersey; public int getJersey() { return this.jersey; } public Athlete(String first_name, String last_name, int jersey) { this.first_name = first_name; this.last_name = last_name; this.jersey = jersey; } } [] athlete.getJersey() = 23; [] athlete.jersey = 23; [] You cannot set the jersey, since jersey is private and there is no setter method. [] athlete.getJersey(23); [] athlete.setJersey(23);
[] athlete.getJersey() = 23; [] athlete.jersey = 23; ∎ You cannot set the jersey, since jersey is private and there is no setter method. [] athlete.getJersey(23); [] athlete.setJersey(23);
Which of the following data types can store real numbers? (select all that apply). [] char [] double [] String [] int [] Float [] Integer
[] char ∎ double [] String [] int ∎ Float [] Integer
The following method is designed to return true if the passed phrase contains either the word cat or dog. public boolean containsPet(String input){ if (input.indexOf("cat") >= 0) { return true; } else if (input.indexOf("dog") >= 0) { return true; } else { return false; } } Which of the following test cases can be used to show the code does NOT work as intended? [] containsPet("My dog caught my cat"); [] containsPet("I don't have pets."); [] containsPet("I have a dog."); [] containsPet("I can catch fish.");
[] containsPet("My dog caught my cat"); [] containsPet("I don't have pets."); [] containsPet("I have a dog."); ∎ containsPet("I can catch fish.");
Which of the following data types is required when the specifier %d is used? [] double [] int [] String [] list [] Double [] ArrayList [] array
[] double ∎ int [] String [] list [] Double [] ArrayList [] array
Given a and b as properly initialized integers, which of the following will result in a real number calculation (*not* integer division) with a decimal answer? [] double y = a / b; [] double y = 1.0 * a / b; [] double y = (double) (a / b); [] double y = a / b * 1.0;
[] double y = a / b; ∎ double y = 1.0 * a / b; [] double y = (double) (a / b); [] double y = a / b * 1.0;
What is output from the following code? String s = "Georgia Tech"; String s1 = s.substring(0,7); String s2 = s1.substring(2); String s3 = s2.substring(0,3); System.out.println(s3); [] eorg [] orgi [] eor [] org [] You will get an index out of bounds exception
[] eorg [] orgi [] eor ∎ org [] You will get an index out of bounds exception
What is the value of s1 after the following code executes? String s1 = "Hey"; String s2 = s1.substring(0,1); String s3 = s2.toLowerCase(); [] h [] H [] Hey [] he
[] h [] H ∎ Hey [] he
What will the following code print? ArrayList<String> list = new ArrayList<String>(); list.add("I"); list.add("love"); list.add("coding"); list.add("in"); list.add("Java"); list.remove(3); System.out.println(list.get(3)); [] in [] It will throw an IndexOutOfBoundsException. [] coding [] Java [] 3
[] in [] It will throw an IndexOutOfBoundsException. [] coding ∎ Java [] 3
Consider the following class: public class Coin { private String name; private double value; public Coin(String theName, double theValue) { name = theName; value = theValue; } public double getValue() { return value; } } Assume that a Coin object quarter has been properly declared and initialized. Which of the following code snippets will successfully assign the value of quarter to a new variable coinWorth? [] int coinWorth = quarter.getValue(); [] double coinWorth = quarter; [] quarter.getValue(); [] double coinWorth = quarter.getValue();
[] int coinWorth = quarter.getValue(); [] double coinWorth = quarter; [] quarter.getValue(); ∎ double coinWorth = quarter.getValue();
A teacher has calculated the gradeAverage as a double, but for report cards, she needs to report it rounded to the nearest whole number. Assuming that we round up from 0.5, which of the following will correctly round the gradeAverage? [] int rcGrade = (int) gradeAverage; [] int rcGrade = (int) gradeAverage + 0.5; [] int rcGrade = gradeAverage % 0.5; [] int rcGrade = (int) (gradeAverage + 0.5); [] int rcGrade = (int) gradeAverage - 0.5;
[] int rcGrade = (int) gradeAverage; [] int rcGrade = (int) gradeAverage + 0.5; [] int rcGrade = gradeAverage % 0.5; ∎ int rcGrade = (int) (gradeAverage + 0.5); [] int rcGrade = (int) gradeAverage - 0.5;
Which of the following declarations will cause a compile time error? [] int[ ] scoreArray = {50,90,85}; [] String[ ] nameArray = new String[10]; [] int[ ] scores = new int[5]; [] int[ ] scores = null; [] String[ ] nameArray = {5, 3, 2};
[] int[ ] scoreArray = {50,90,85}; [] String[ ] nameArray = new String[10]; [] int[ ] scores = new int[5]; [] int[ ] scores = null; ∎ String[ ] nameArray = {5, 3, 2};
Which of the following code segments will correctly create an instance of a Person object? public class Person { private String name; private int age; public Person(String a, int b) { name = a; age = b; } } [] new Person john = Person("John", 16); [] Person john("John", 16); [] Person john = ("John", 16); [] Person john = new Person(16, "John"); [] Person john = new Person("John", 16);
[] new Person john = Person("John", 16); [] Person john("John", 16); [] Person john = ("John", 16); [] Person john = new Person(16, "John"); ∎ Person john = new Person("John", 16);
The Insect class will contain a String for the insect's name, an int for the number of legs it has, and a boolean for whether or not the insect has wings. Which of the following is the most appropriate implementations for the Insect Class? [] private class Insect { public String name; public int numLegs; public boolean hasWings; //constructor and methods not shown } [] public class Insect { public String name; private int numLegs; private boolean hasWings; //constructor and methods not shown } [] private class Insect { String name; int numLegs; boolean hasWings; //constructor and methods not shown } [] public class Insect { String name; int numLegs; boolean hasWings; //constructor and methods not shown } [] public class Insect { private String name; private int numLegs; private boolean hasWings; //constructor and methods not shown }
[] private class Insect { public String name; public int numLegs; public boolean hasWings; //constructor and methods not shown } [] public class Insect { public String name; private int numLegs; private boolean hasWings; //constructor and methods not shown } [] private class Insect { String name; int numLegs; boolean hasWings; //constructor and methods not shown } [] public class Insect { String name; int numLegs; boolean hasWings; //constructor and methods not shown } ∎ public class Insect { private String name; private int numLegs; private boolean hasWings; //constructor and methods not shown }
Write a method that will ask for user input until user inputs the String "no". Allow the user to input any capitalization of the String "no" ("no", "No", "NO", "nO") Also, have the method return the number of loops. Assume that a Scanner object input has already been created. [] public int loopTillNo() { int count = 0; String nextLine = ""; while(!nextLine.equals("no")) { nextLine = input.nextLine(); count++; } return count; } [] public int loopTillNo() { int count = 0; String nextLine = ""; while(nextLine.toLowerCase().equals("no")) { nextLine = input.nextLine(); count++; } return count; } [] public int loopTillNo() { int count = 0; String nextLine = ""; while(!nextLine.toLowerCase().equals("no")) { nextLine = input.nextLine(); count++; } return count; } [] public int loopTillNo() { int count = 0; String nextLine = ""; while(nextLine.equals("no")) { nextLine = input.nextLine(); count++; } return count; }
[] public int loopTillNo() { int count = 0; String nextLine = ""; while(!nextLine.equals("no")) { nextLine = input.nextLine(); count++; } return count; } [] public int loopTillNo() { int count = 0; String nextLine = ""; while(nextLine.toLowerCase().equals("no")) { nextLine = input.nextLine(); count++; } return count; } ∎ public int loopTillNo() { int count = 0; String nextLine = ""; while(!nextLine.toLowerCase().equals("no")) { nextLine = input.nextLine(); count++; } return count; } [] public int loopTillNo() { int count = 0; String nextLine = ""; while(nextLine.equals("no")) { nextLine = input.nextLine(); count++; } return count; }
Write a method that loops until the user inputs the correct secret password or until the user fails to enter the correct password 10 times. The secret password the program should look for is the String "secret" Assume that a Scanner object called input has been correctly initialized. [] public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); } String readLine = input.nextLine(); if(readLine.equals("secret")) { System.out.println("Welcome!"); } count++; } } [] public void secretPassword() { int count = 0; while(true) { if(count != 10) { System.out.println("You are locked out!"); return; } String readLine = input.nextLine(); if(!readLine.equals("secret")) { System.out.println("Welcome!"); return; } count++; } } [] public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } String readLine = input.nextLine(); if(readLine.equals("secret")) { System.out.println("Welcome!"); return; } count++; } } [] public void secretPassword() { int count = 1; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } String readLine = input.nextLine(); if(readLine.equals("secret")) { System.out.println("Welcome!"); return; } count++; } }
[] public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); } String readLine = input.nextLine(); if(readLine.equals("secret")) { System.out.println("Welcome!"); } count++; } } [] public void secretPassword() { int count = 0; while(true) { if(count != 10) { System.out.println("You are locked out!"); return; } String readLine = input.nextLine(); if(!readLine.equals("secret")) { System.out.println("Welcome!"); return; } count++; } } ∎ public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } String readLine = input.nextLine(); if(readLine.equals("secret")) { System.out.println("Welcome!"); return; } count++; } } [] public void secretPassword() { int count = 1; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } String readLine = input.nextLine(); if(readLine.equals("secret")) { System.out.println("Welcome!"); return; } count++; } }
The purpose of an accessor method is [] to return the values of all of the instance variables [] to return the value of an instance variable [] to modify an instance variable [] to allow the user to have direct access to an instance variable
[] to return the values of all of the instance variables ∎ to return the value of an instance variable [] to modify an instance variable [] to allow the user to have direct access to an instance variable
The purpose of a mutator method is [] to return the values of all of the instance variables [] to safely modify an instance variable [] to return the value of an instance variable [] to allow the user to have direct access to an instance variable
[] to return the values of all of the instance variables ∎ to safely modify an instance variable [] to return the value of an instance variable [] to allow the user to have direct access to an instance variable
Given int a = 3; int b = 5; int c = 2; int d = 3; What do u and v evaluate to? boolean u = a == d; boolean v = d >= b; [] u = false v = true [] u = true v = true [] u = true v = false [] u = false v = false
[] u = false v = true [] u = true v = true ∎ u = true v = false [] u = false v = false
What are the values of var1 and var2 after the following code segment is executed and the while loop finishes? int var1 = 0; int var2 = 2; while ((var2 != 0) && ((var1 / var2) >= 0)) { var1 = var1 + 1; var2 = var2 - 1; } [] var1 = 1, var2 = 1 [] var1 = 3, var2 = -1 [] The loop won't finish executing because of a division by zero. [] var1 = 0, var2 = 2 [] var1 = 2, var2 = 0
[] var1 = 1, var2 = 1 [] var1 = 3, var2 = -1 [] The loop won't finish executing because of a division by zero. [] var1 = 0, var2 = 2 ∎ var1 = 2, var2 = 0
Given the following: if (x > y) { y *= 2; } else if (y > x) { x *= 2; } if (x > y) { y *= 2; } if (y > x) { x *= 2; } What will the final values of x and y be if their initial values are: x = 12 y = 5 [] x = 12 y = 10 [] x = 24 y = 20 [] x = 12 y = 20 [] x = 24 y = 5
[] x = 12 y = 10 ∎ x = 24 y = 20 [] x = 12 y = 20 [] x = 24 y = 5
Assume y is a properly initialized positive integer. Which of the following will always result in a value of 1? [] y += y; [] y ++; [] y -= y; [] y /= y; [] y --;
[] y += y; [] y ++; [] y -= y; ∎ y /= y; [] y --;
Given the following java code, give the full name of the file including the extension (an extension for a Microsoft Word file is .docx, a PDF file is.pdf, etc). public class addition { public static void main(String[] args) { int x = 5; int y = 6; int sum; sum = x + y; System.out.println(sum); } } Full name of file:
addition.java
The Boolean AND (&&) requires ______ conditions to be true for the entire statement to be true.
all
The Boolean OR (||) requires ________ conditions to be true for the entire statement to be true.
at least one
class test { public static void main(String[] args) { int a; int b; /* ... */ XXXX cond = a != b; } } What data type would I use for XXXX?
boolean
A field with the ________ keyword means that the field cannot be changed after being set once.
final
Given the code snippet below: int i = 10; int j = 20; System.out.println(XXX); I want to have "10 20" (that is, ten space twenty) outputted to the screen. Replace XXX using the variables i and j to finish the print statement to accomplish this task. Replace XXX:
i + " " + j
What import statement must I use in order for java to use the scanner? import ______;
java.util.Scanner
Given the following code: Dog puppy = ???? Write the code for ???? that will create a new instance of a Dog object using the default constructor:
new Dog();
What will this code return given checkMethod(false, true)? public int checkMethod(boolean x, boolean y) { if(!x) { if(y) { return -1; } else { return 1; } } else { return 0; } } [] -1 [] 1 [] 0 [] This method call will error.
∎ -1 [] 1 [] 0 [] This method call will error.
What will the following code print? int n = 5; n ++; n ++; n += n; System.out.println(n); [] 14 [] 12 [] 40 [] 18
∎ 14 [] 12 [] 40 [] 18
How many times will the word "Heyo!" be printed in the following code segment? int count = 3; while(count <= 7) { for(int i = 2; i < 5; i++) { System.out.println("Heyo!"); } count ++; } [] 15 [] 12 [] 9 [] 16 [] 20
∎ 15 [] 12 [] 9 [] 16 [] 20
What is the output after this code snippet runs? int[] scores = {80, 92, 91, 68, 88}; int i = 0; while (i < scores.length - 1) { System.out.println(scores[i] * 2); i ++; } [] 160 184 182 136 [] 160 184 182 136 176 [] 184 182 136 [] Infinite loop
∎ 160 184 182 136 [] 160 184 182 136 176 [] 184 182 136 [] Infinite loop
What does the following code print? for (int i = 3; i <= 12; i++) { System.out.print(i + " "); } [] 3 4 5 6 7 8 9 10 11 12 [] 4 5 6 7 8 9 10 11 12 [] 3 5 7 9 11 [] 5 6 7 8 9
∎ 3 4 5 6 7 8 9 10 11 12 [] 4 5 6 7 8 9 10 11 12 [] 3 5 7 9 11 [] 5 6 7 8 9
What will be the output of the following code snippet? int[] scores = {80, 92, 91, 68, 88}; int myIndex = 0; for (int i = 1; i < scores.length; i++) { if (scores[i] < scores[myIndex]) { myIndex = i; } } System.out.println(scores[myIndex]); [] 68 [] 3 [] 92 [] 88
∎ 68 [] 3 [] 92 [] 88
The following code is intended to print 8. int x = 23; double y = 3; System.out.println((int)(x / y)); What is printed and why? [] 7 becausex / y calculates to 7.66 then the cast to an int results in the value getting truncated to 7 [] 8 because the values of x and y are integers so 23 / 3 evaluated to 8 [] 7 because the values of x and y are integers so 23 / 3 evaluated to 7 [] 8 because x / y calculates to 7.66 then the cast to an int results in the value getting rounded up to 8
∎ 7 becausex / y calculates to 7.66 then the cast to an int results in the value getting truncated to 7 [] 8 because the values of x and y are integers so 23 / 3 evaluated to 8 [] 7 because the values of x and y are integers so 23 / 3 evaluated to 7 [] 8 because x / y calculates to 7.66 then the cast to an int results in the value getting rounded up to 8
What will this program print if the value of grade is 80? if(grade > 90) { System.out.println("A"); } else if(grade > 80) { System.out.println("B"); } else if(grade > 70) { System.out.println("C"); } [] C [] B [] A [] Nothing
∎ C [] B [] A [] Nothing
What is the difference between instance variables and static variables? [] Each object has its own copy of the instance variables, but all objects share a copy of the static variables [] Instance variables can be public or private, but static variables must be public [] Each object has its own copy of the static variables, but all objects share a copy of the instance variables [] Static variables can be public or private, but instance variables must be private
∎ Each object has its own copy of the instance variables, but all objects share a copy of the static variables [] Instance variables can be public or private, but static variables must be public [] Each object has its own copy of the static variables, but all objects share a copy of the instance variables [] Static variables can be public or private, but instance variables must be private
What does the following code snippet check for? int[] numbers = {1, 2, 3, 3, 4, 5}; boolean mysteryBoolean = false; for (int i = 0; i < numbers.length - 1; i++) { for (int j = i + 1; j < numbers.length; j++) { if (numbers[i] == numbers[j]) { mysteryBoolean = true; } } } [] Finds duplicate values in an array [] Reorders the array from smallest to largest value [] Accesses all consecutive pairs of elements [] Reorders the array from largest to smallest value
∎ Finds duplicate values in an array [] Reorders the array from smallest to largest value [] Accesses all consecutive pairs of elements [] Reorders the array from largest to smallest value
What does the following code print? int x = 2; while (x < 8) { System.out.print(x + " "); } [] It is an infinite loop [] 0 1 2 3 4 5 6 7 8 [] 2 3 4 5 6 7 [] 0 1 2 3 4 5 6 7 [] 2 3 4 5 6 7 8
∎ It is an infinite loop [] 0 1 2 3 4 5 6 7 8 [] 2 3 4 5 6 7 [] 0 1 2 3 4 5 6 7 [] 2 3 4 5 6 7 8
Which of the following is a benefit of using a mutator method? [] Mutator methods can verify the new value is a valid value for the instance variable [] Only methods outside of the class can change an instance variable's value [] The user can change all of the instance variables using the same mutator method [] Only methods inside the class can change an instance variable's value
∎ Mutator methods can verify the new value is a valid value for the instance variable [] Only methods outside of the class can change an instance variable's value [] The user can change all of the instance variables using the same mutator method [] Only methods inside the class can change an instance variable's value
What value will be printed in the console after this series of commands? Assume that the ArrayList package has been imported. ArrayList<String> names = new ArrayList<String>(); names.add("Michael"); names.add("Lebron"); names.add("Serena"); names.add("Shaq"); String firstName = names.remove(0); String secondName = names.set(0, "Venus"); names.add(2, firstName); System.out.println("Names:" + secondName + " and " + names.get(1)); [] Names: Lebron and Serena [] Names: Michael and Shaq [] Names: Lebron and Michael [] This will cause an error, as names.remove cannot be assigned to a value. [] Names: Venus and Serena
∎ Names: Lebron and Serena [] Names: Michael and Shaq [] Names: Lebron and Michael [] This will cause an error, as names.remove cannot be assigned to a value. [] Names: Venus and Serena
What will this code output? if (true && true && false) { System.out.println("Hello Karel"); } if (true && 4 == 2 + 2) { System.out.println("Second if statement!"); } [] Second if statement! [] This program will print nothing [] Hello Karel [] Hello Karel Second if statement!
∎ Second if statement! [] This program will print nothing [] Hello Karel [] Hello Karel Second if statement!
Which of the following is not a primitive type? [] String [] int [] boolean [] char [] double
∎ String [] int [] boolean [] char [] double
Which of the following is NOT a characteristic of a mutator? [] The method returns the value of an instance variable [] The method updates an instance variable's value [] The method's name (usually) starts with set [] The method changes the value of an instance variable to a user's specified value
∎ The method returns the value of an instance variable [] The method updates an instance variable's value [] The method's name (usually) starts with set [] The method changes the value of an instance variable to a user's specified value
Any integer % 1 = 0 [] True [] False
∎ True [] False
Does the following Boolean expression evaluate to true or false, given x = 10 and y = 5? (x != y) && (0 < x) && ((y < 10) || (x == y)) [] True [] False
∎ True [] False
What will print when the following code executes? ArrayList<String> list1 = new ArrayList<String>(); list1.add("Anaya"); list1.add("Layla"); list1.add("Sharrie"); list1.set(0, "Destini"); list1.add(0, "Sarah"); System.out.println(list1); [] ["Sarah", "Destini", "Layla", "Sharrie"] [] ["Destini", "Layla", "Sharrie", "Sarah"] [] ["Sarah", "Layla", "Sharrie"] [] ["Sarah", "Destini", "Anaya", "Layla", "Sharrie"]
∎ ["Sarah", "Destini", "Layla", "Sharrie"] [] ["Destini", "Layla", "Sharrie", "Sarah"] [] ["Sarah", "Layla", "Sharrie"] [] ["Sarah", "Destini", "Anaya", "Layla", "Sharrie"]
Given the following code segment, what is the value of num when it finishes executing? double value = Math.random(); int num = (int) (value * 11) - 5; [] a random number from -5 to 5 (inclusive) [] a random number from 0 to 9 (inclusive) [] a random number from -5 to 4 (inclusive) [] a random number from 0 to 10 (inclusive)
∎ a random number from -5 to 5 (inclusive) [] a random number from 0 to 9 (inclusive) [] a random number from -5 to 4 (inclusive) [] a random number from 0 to 10 (inclusive)
Which methods of class Foo can be called without an actual instance of the class Foo? public class Foo { public static void foo() { ... } public void bar() { ... } public void baz() { ... } } [] foo() [] All methods require an instance of Foo in order to be called. [] No methods require an instance of Foo in order to be called. [] bar() [] baz()
∎ foo() [] All methods require an instance of Foo in order to be called. [] No methods require an instance of Foo in order to be called. [] bar() [] baz()
The return type of a mutator method [] is usually void [] must be a user defined class [] must be a primitive [] must match the type of of the instance variable being mutated
∎ is usually void [] must be a user defined class [] must be a primitive [] must match the type of of the instance variable being mutated
Which of the following is true about a constructor? (select all that apply) [] it has no return type. [] it has the same name as the class. [] its return type is the class name [] there can be multiple constructors. [] it can be called more than once with the same instance
∎ it has no return type. ∎ it has the same name as the class. [] its return type is the class name ∎ there can be multiple constructors. [] it can be called more than once with the same instance
The return type of an accessor method [] must match the type of the instance variable being accessed [] is void [] must be a user defined class [] must be a primitive
∎ must match the type of the instance variable being accessed [] is void [] must be a user defined class [] must be a primitive
Given int a = 3; int b = 5; int c = 2; int d = 3; What do w and x evaluate to? boolean w = b > c; boolean x = a != d; [] w = true x = false [] w = false x = true [] w = true x = true [] w = false x = false
∎ w = true x = false [] w = false x = true [] w = true x = true [] w = false x = false
Which expression returns the 1's place of an integer x? [] x % 10 [] x % 100 [] x / 10 [] x + 1
∎ x % 10 [] x % 100 [] x / 10 [] x + 1
What values for x and y will cause the program to execute the /* missing code */? if (x > 10) { x -= 5; if (x > 10 || y <= 10) { x ++; y++; } else { /* missing code */ } } [] x = 12 y = 12 [] x = 18 y = 18 [] x = 12 y = 8 [] x = 18 y = 12 [] x = 18 y = 8
∎ x = 12 y = 12 [] x = 18 y = 18 [] x = 12 y = 8 [] x = 18 y = 12 [] x = 18 y = 8