Stem Tech Final Exam

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What will this method call print? public void patternGrid(int rows, int columns, char symbol) { for(int m = 0; m < rows; m++) { for(int n = 0; n < columns; n++) { System.out.print(symbol); } System.out.println(); } } patternGrid(3,4,'#'); A) #### #### #### B) ### ### ### C) #### #### #### #### D) This code will error.

A) #### #### ####

What is the output of this for loop? for(int i = 10; i > 2; i -= 3) { System.out.println(i); } A) 10 7 4 B) 10 7 4 1 C) 1 2 3 D) 10 8 6 4 2

A) 10 7 4

What will this method call print to the screen? public void numberMadness(double myDouble) { int myInt = (int) myDouble; String myString = ""; while(myInt != 0) { myString = myInt % 10 + myString; myInt /= 10; } System.out.println(myString); } numberMadness(12345) A) 12345 B) 54321 C) 123 D) 543

A) 12345

What is a method? A) A procedure that is defined by the user. B) A keyword used to loop for a fixed amount of time. C) A place where we can store data. D) The type that is given to a variable.

A) A procedure that is defined by the user.

What is the difference between a class and an object? A) Objects are instances of classes. The class is the general template, and the object is the specific version. B) Classes are instances of objects. The object is the general template, and the class is the specific version. C) A class has a run method or main method but an object does not. D) An object is a way to refer to a Java program and a class refers to the programming environment.

A) Objects are instances of classes. The class is the general template, and the object is the specific version.

What is the name of the method to print out text in Java? A) System.out.println() B) System.out.printline() C) System.output() D) System.out.PRINTLN()

A) System.out.println()

What is the output of this for loop? for(int i = 0; i < 100; i += 2) { System.out.println(i); } A) The even numbers from 0 to 98, inclusive B) The even numbers from 0 to 100, inclusive C) All of the numbers from 0 to 100 D) The odd numbers from 0 to 98, inclusive

A) The even numbers from 0 to 98, inclusive

What could the method signature for a Karel command look like? A) public void move() { //some code } B) public String move() { //some code } C) public int move() { //some code } D) public boolean move() { //some code }

A) public void move() { //some code }

Which expression returns the 1's place of an integer x? A) x % 10 B) x / 10 C) x % 100 D) x + 1

A) x % 10

Which expression is true? A) true && !true B) !false || !true C) true && false D) false || false || !true

B) !false || !true

What will this method call output? public String yesOrNo(boolean myBoolean) { if(myBoolean == true) { return "Yes"; } else { return "No"; } } yesOrNo(true) A) "No" B) "Yes" C) 0 D) This program will error

B) "Yes"

What is returned by this method call: translator("pokemon")? public String translator(String word) { return word.substring(1) + word.charAt(0) + "ay"; } A) "pokemonpay" B) "okemonpay" C) "okemonay" D) This method call will error.

B) "okemonpay"

What will the code segment output? for (int m = 5; m > 0; m--) { for(int n = m; n > 0; n--) { System.out.print("*"); } System.out.println(); } A) * ** *** **** ***** B) ***** **** *** ** * C) ***** ***** ***** ***** ***** D) ***************

B) ***** **** *** ** *

What will the value of yourBankAccount be after the method call? int yourBankAccount = 0; public void depositMoney(int bankAccount, int deposit) { bankAccount += deposit; } depositMoney(yourBankAccount, 1000000); A) 1000000 B) 0 C) 100000 D) The code will error.

B) 0

What will this method call output? public int myMethod(boolean x, boolean y) { if(!x) { if(y) { return 1; } else { return 0; } } else { return -1; } } myMethod(false,false) A) 1 B) 0 C) -1 D) This method call will error.

B) 0

Which of these is not a valid Java method name? A) spin10Times B) 10TimesMove C) moveTenTimes D) spinTenTmes

B) 10TimesMove

What is the result of this expression? 5 + 2 / 3 + 1 A) 5 B) 6 C) 6.67 D) 0

B) 6

What is an object in Java? A) An object is a template for how to make new programs in Java. B) An object is something that contains both state and behavior. C) An object is a single part of a computer program. D) An object is a list of variables.

B) An object is something that contains both state and behavior.

What is wrong with this method definition? public String outputString(String input) { System.out.println(input); } A) The method should not be public B) Improper return value C) Improper variable names D) All of the above

B) Improper return value

What kind of error does this method cause? public void buggyMethod(String x) { for(int i = 0; i <= x.length(); i++) { System.out.println(x.substring(i, i+1)); } } buggyMethod("BUG"); A) Compile Time Error: Unexpected return value B) Runtime Error: String index out of range C) Compile Time Error: Missing return value D) Compile Time Error: Syntax Error in method definition

B) Runtime Error: String index out of range

What is the output of the following lines? int x = 24; System.out.println("The total is " + x + x); A) The total is 24 B) The total is 2424 C) The total is 48 D) The total is x + x

B) The total is 2424

What is the output of this program? int sum = 1; System.out.println("Welcome to the adding machine!"); while(sum < 10) { sum += sum; System.out.println(sum); } A) Welcome to the adding machine! 1 2 4 8 16 B) Welcome to the adding machine! 2 4 8 16 C) Welcome to the adding machine! 2 4 8 D) This code has an infinite loop.

B) Welcome to the adding machine! 2 4 8 16

Refer to the following code segment: double myDouble = 1/4; System.out.println("1 / 4 = " + myDouble); The output of the code is: 1 / 4 = 0.0 The student wanted the output to be: 1 / 4 = 0.25 Which change to the first line of their code segment would get the student the answer that they wanted? A) int myDouble = 1/4; B) double myDouble = (double) 1/4; C) double myDouble = (int) 1/4; D) double myDouble = (int) (1.0/4.0);

B) double myDouble = (double) 1/4;

What is the proper syntax to initialize a double called temperature to have the value 70.4? A) int temperature = 70.4; B) double temperature = 70.4; C) temperature = 70.4; D) float temperature = 70.4;

B) double temperature = 70.4;

What does this method call output? public double doubleOrNothing(double myDouble) { return (double) (int) myDouble * 2; } doubleOrNothing(9.9); A) 20 B) 18.8 C) 18.0 D) This method is improperly written.

C) 18.0

What will this method call output? public int mysteryMethod(String x, char y) { int z = 1; for(int i = 0; i < x.length(); i++) { if(x.charAt(i) == y) { z++; } } return z; } mysteryMethod("Karel The Dog", 'e'); A) 1 B) 2 C) 3 D) 4

C) 3

What is the value of x after this code? int x = 5; x = 10; x = 4; A) 5 B) 10 C) 4 D) true

C) 4

How many times will the loop execute? int i = 0; while(i < 50) { System.out.println(i); i += 10; } A) 0 B) 4 C) 5 D) 50

C) 5

What is the value of myInteger after this line of code? int myInteger = (int) 5.6; A) 6 B) 5.5 C) 5 D) 9

C) 5

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"); } A) A B) B C) C D) Nothing

C) C

What output will be produced by System.out.println("Hello"); System.out.println("Karel"); A) Hello Karel B) HelloKarel C) Hello Karel D) Error

C) Hello Karel

What are parameters? A) The value that a method returns. B) The values that a method prints to the screen. C) The formal names given to the data that gets passed into a method. D) The type that is given to a variable.

C) The formal names given to the data that gets passed into a method.

What does void mean? A) Void means that a method returns any value. B) Void means that a method takes no parameters. C) Void means that a method returns no value. D) Void means that a method can take any parameter.

C) Void means that a method returns no value.

Which of these is not a valid Java method name? A) runInCircles B) jumpHurdle C) find tower D) finishMaze

C) find tower

Write a method that loops forever 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" Use readLine(String prompt) for user input A) public void secretPassword() { int count = 1; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } if(readLine("Password?").equals("secret")) { System.out.println("Welcome!"); return; } count++; } } B) public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); } if(readLine("Password?").equals("secret")) { System.out.println("Welcome!"); } count++; } } C) public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } if(readLine("Password?").equals("secret")) { System.out.println("Welcome!"); return; } count++;} } D) public void secretPassword() { int count = 0; while(true) { if(count != 10) { System.out.println("You are locked out!"); return; } if(!readLine("Password?").equals("secret")) { System.out.println("Welcome!"); return; } count++; } }

C) public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } if(readLine("Password?").equals("secret")) { System.out.println("Welcome!"); return; } count++;} }

Which of the following is not a primitive type? A) int B) double C) String D) boolean E) char

C) string

Which of these is not a logical operator? A) && B) ! C) || D) ++

D) ++

What is the result of this expression? 4 + 8 * 3 / 4 + 5 % 2 A) 5 B) 6 C) 12 D) 11

D) 11

What does this method call output? public int trickyMethod(int x, int y) { int sum = 0; while (x <= 10) { sum += x % y; x++; y++; } return sum; } trickyMethod(3,1) A) 9 B) 10 C) 11 D) 12

D) 12

What is the return value of this method call? public static String someWhereInTheMiddle(int number) { String stringNum = "" + number; int middle = stringNum.length()/2; if(stringNum.length() % 2 == 1) { return stringNum.substring(middle,middle+1); } else { return stringNum.substring(middle-1,middle+1); } } someWhereInTheMiddle(188603) A) 8 B) 6 C) 7 D) 86

D) 86

What is a Javadoc? A) The reference guide to Java that is in the back of a textbook. B) A program that cures the bugs in your Java program. C) Data that gets passed into a method D) A comment that clearly states the functionality and usage of a class or method.

D) A comment that clearly states the functionality and usage of a class or method.

Why do we use methods in Java? A) To make code easier to understand B) To avoid repeated code C) To simplify code D) All of the above

D) All of the above

What in this code segment could potentially cause a bug in our program? String myString = readLine("What is your name?"); if (myString == "Karel") { System.out.println("Hi Karel!"); } else { System.out.println("You're not Karel!"); } A) Syntax error in the if statement B) Nothing C) Trying to store a Line in a String variable. D) Comparing Strings with == instead of the .equals method.

D) Comparing Strings with == instead of the .equals method.

What will this method call print to the screen? public static void someMethod(int a, String b, int c) { System.out.println(b + " " + a + ", " + c); } someMethod(9,"Mar", 1250) A) 9 Mar 1250 B) Mar 9 1250 C) 9, Mar 1250 D) Mar 9, 1250

D) Mar 9, 1250

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!"); } A) Hello Karel B) Hello Karel Second if statement! C) This program will print nothing D) Second if statement!

D) Second if statement!

What is a return value? A) The value that a method prints to the screen. B) The value that is inputted to a method. C) The value that a user inputs to a program. D) The value that a method outputs.

D) The value that a method outputs.

What does this method call return? public int doubleInt(int x) { x * 2; } doubleInt(5); A) 10 B) 5 C) This method returns nothing. D) This method is improperly written.

D) This method is improperly written.

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. Use readLine to get the user input. A) public int loopTillNo() { int count = 0; while(!readLine("Again?").equals("no")) { count++; } return count; } B) public int loopTillNo() { int count = 0; while(readLine("Again?").toLowerCase().equals("no")) { count++; } return count; } C) public int loopTillNo() { int count = 0; while(readLine("Again?").equals("no")) { count++; } return count; } D) public int loopTillNo() { int count = 0; while(!readLine("Again?").toLowerCase().equals("no")) { count++; } return count; }

D) public int loopTillNo() { int count = 0; while(!readLine("Again?").toLowerCase().equals("no")) { count++; } return count; }

What will this method call output? public boolean someMethod(int number) { if(number % 2 == 0) { return true; } else { return false; } } someMethod(9990) A) false B) 0 C) "true" D) true

D) true

What will the values of x and y be after this code segment runs? int x = 100; int y = 100; if (x <= 100) { if (y > 100) { x = 200; } else { x = 99; } } else { x++; } y = x + y; A) x = 100 y = 200 B) x = 101 y = 100 C) x = 101 y = 201 D) x = 99 y = 199

D) x = 99 y = 199

What would this method call output? public int myMethod(int num) { while(num / 10 >= 10) { num /= 10; } return num; } myMethod(830) a) 830 B) 30 C) 0 D) 8 E) 83

E) 83

Which of these characters can a Java method name start with? (I) Letters (II) Numbers (III) Underscore (IV) $ Sign A) I only B) and II C) II only D) I and III E) I, III, and IV

E) I, III, and IV


संबंधित स्टडी सेट्स

Chapter 30: Aggregate Demand and Aggregate Supply

View Set

모벍쌤 시험 총정리 퀴즐렛

View Set

dispositivos de control de tránsito

View Set

Series 65 - investment suitability

View Set