RPA 2 CS 164

¡Supera tus tareas y exámenes ahora con Quizwiz!

Given the following code, what is printed? public static double getAnswer(int first, int second) { return 4 * first * second; } public static void main(String[] args) { int val = 8; int val2 = 9; System.out.println(getAnswer(val, val2)); }

288

Given the following code, what is printed? int val = 19 % 8;System.out.println(val);

3

Given the following code, what is printed? int val = 17 % 2;System.out.println(val);

1

Order the parts to create method that is the main entry point to the program.

1) public 2) static 3) void 4) main 5) ( 6) String[] 7) args 8) ) 9) { 10) /* some additional code here */ 11) }

You goal is to build a line of code prints the "Row" and "Seat" number for a student, given a whole number value that has been assigned to them. You can assume stuSeat is an int that has been validly set. You can also assume the max number of seats in a row is 20, and that all rows are the same length. You do not have to store the answer, so just print it out - as such, making it a single line of code. We can safely start counting at 0 for both rows and seats.

1)System.out.println("Row: " + 2)stuSeat / 20 3)+ " Seat: " 4) + 5) stuSeat % 20 6) );

Match the type with the best definition: 1) True or False 2)Whole numbers 3)A collection of characters in a set order 4)Single Letter, digit, etc 5)Numbers with decimals

1)boolean 2)int 3)String 4)char 5)double

Given the following memory tables (final result), and the following class - order the main method. (see picture)

1)public static void main(String[] args) { 2)int x = 10; KC one = new KC(); KC two = new KC(); // placed on same line to make ordering easier 3)double y = x / 2; 4)one.setValue(y); 5)two.setValue(one.getValue()); 6)one.setValue(x); 7)}

Write a Java statement that declares a variable named hoursSlept of type int, and initializes its value to 314159. Do not forget the semi-colon. Follow basic java syntax in using proper spaces - else it won't be graded correctly.

int hoursSlept = 314159;

Given the following code: public static String welcome(String basic, String greeting) { return greeting + ", " + basic; } And the following is printed to the screen: Welcome, Who Complete the statement below with the correct method call and parameters. System.out.println(_______);

welcome("Who", "Welcome")

Given the following code, what is printed? int val = 22 % 9;System.out.println(val);

4

Given the following code, what is printed? (see picture)

A2

Given the following code, what is printed? (see picture)

C

True or False? Modulo can allow you to create a range between 1 and n, where n is the value you use. For example:x % 6, will create a range between 1 and 6, no matter the size of x. True False

Flase

Given the following code, what is printed? (see picture)

LINK Link L k

Given the following code, match the label with the best definition: Label 1: Label 2: Label 3: Label 4: Label 5:

Label 1: instance variables Label 2: Instance Method Label 3: Static method Label 4: Local method variables Label 5:Constructs Object

Categorize the following types. Primitive and Objects: char boolean double int String Scanner

Primitive (anything lower case): char boolean double int Object(anything upper case): String Scanner

True or False? Modulo can allow you to create a range between 0 and n-1, where n is the value you use. For example:x % 6, will create a range between 0 and 5, no matter the size of x. True False

True

Given the following blocks of code, categorize them as valid (they will compile) or invalid (they will not compile) Invalid Valid

Valid: 1)int val1 = 10, val2 = 5; 2)int val1, val2, val3; 3)String dbl = " "; 4)char s = 'S'; 5)double _PI = 3.14; 6)String name = "Spot!"; 7)double puppyCost = 100; 8)int val = 0; double val2 = val; 9)int puppyCounter = 0; Invalid: 1)int $counter$ = 0 2)double val = 1.1; int val3 = val; 3)int 3val = 3; 4)int new = 10; 5)char shorter = "S"; 6)int val =1, double val2 = 2.0; 7)String single = ' '; 8)int counter = 1.1;

Mark the following code as valid or not. Valid Invalid

Valid: 1)public double calcArea(double w, double h) {} 2)public static void main(String[] args) { } 3)public void doSomething() {} Invalid: 1)Public static void doAnotherSomething() {} 2)public static void $doSomething(int, double) {} 3)public static void main(String[] args);

Group code into valid or invalid - invalid can include both code that doesn't compile, and code that compiles but would return a runtime error. Valid: Invalid:

Valid: 1)char x = 67; 2)char x = "Raven".charAt(0); 3)String clara = "Raven" + '_' + "nevermore"; 4)int nevermore = 'R' + 'a' + 'v' + 'e' + 'n'; 5)int val = 'x' + 2; Invalid: 1)String number = 10 + 'x'; 2)string stich = "lilo"; 3)String nevermore = "Raven"; char x = nevermore.charAt(nevermore.length()); 4)String joe = 'joe'; 5)int number = 10 + "x";

Match the following with the definition. What can only contain numeric style values?: What contains the recipe for an object?: What contains data and actions/methods relative to that? data.: What do you call variables declared in the method signature?: What is a variable that exist with each instance of an object?: What is a block of executable code in a class?: What is a keyword used to reference the current instance of an object?:

What can only contain numeric style values?: primitive What contains the recipe for an object?: class What contains data and actions/methods relative to that? data.: object What do you call variables declared in the method signature?: parameters What is a variable that exist with each instance of an object?: instance variable What is a block of executable code in a class?: method What is a keyword used to reference the current instance of an object?: this

Given the following code, what is printed? (see picture)

ZELDA Zelda Z a


Conjuntos de estudio relacionados

Stress Management ch.3 Stress and Illness Disease

View Set

EXAM 1 (Chapters 1-5) Business Strategy

View Set