Java Unit4-

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Provide the correct syntax in the Java code below to display an output of 12. public static void main(String[] args){ int num = 10;___________ System.out.println(++num);

a.num++; b.(++num)

Given a variable foo, what is the correct syntax of implementing a switch-case statement with this variable? Select one:

switch(foo)

Match the Short-Circuit Operator Symbol with its corresponding Description Short Circuit OR | | Short Circuit AND &&

Short Circuit OR | | Short Circuit AND &&

The six relational operators are ideally used for primitive data types but NOT for String comparisons.

True

All operators in the list are considered as binary operators, which means you need two (2) operands in order for you to use the said operators, but the ! operator is considered as a Unary operator because you only need one operand to operate on.

!

The Unicode integer value of 'a' is 97 (base 10). Given the code snippet: char ch = 'a'; System.out.println(ch + 1); What will be the output if the given code was embedded within a working code?

98

Match the Java Relational Operator with its description. <=less than equal to >= more than equal to > more than < less than == equal to !=not equal to

<=less than equal to >= more than equal to > more than < less than == equal to !=not equal to

What is the symbol used to test for equality?

==

What is the data type returned by a Logical Expression?

? a. boolean b. byte

The ternary operator is represented by ?: symbol.

?:

Arithmetic operators are used in mathematical expressions in the same way that they are used in

Algerbra

Given the snippet below: String s1 = "Silicon"; String s2 = " Valley"; s1 += s2; Which of the statements below is correct? Choose two.

Both- The value of s2 is still " Valley", it did not change The value of s1 is Silicon Valley

Given the Java code snippet below: int num1 = 23; int num2 = 8; System.out.println((num1 ++ num2) + num1); What is the output?

Compilation Error

Given: num1 = 20; num2 = 5; int result = num1 (put operator here) num2; What operator should we use so that the value of result will be 4?

Division Operator ( / )

Given two boolean variables: boolean a = true; boolean b = false; boolean result = // put code here Which of the options below will assign false to variable result? Choose three. Select one or more:

all- !a && b !a && !b a && b

Which of these is NOT a Logical Operator?

+

The legal range of a char data type is from 0 to'\uffff'

0 to '\uffff'

What is the symbol of the Not Equal (or Inequal) Operator?

!=

Given: String str1 = "Silicon Valley"; String str2 = new String (str1); Provide the appropriate Relational Operation inside the println method to return a value of true. System.out.println(___________);

str1.equals(str2)

Fill in the correct Assignment Operator to display an output of 27. int num1 = 9; int num2 = 3; System.out.println(num1 *= num2);

*=

Given the snippet below: public static void main(String[] args){ int num = 10; System.out.println(___________); } What should be the value placed in the println method so that the output will be 11?

++num

The legal range of a byte is from -128 to ?

-128 to? not- 128 0

What is the value of 8 - 6 / 2 * 4 + 1 ?

-3

Given the code below: int num = 40; num += 5; num /=9; num -= 3; What is now the value of variable num?

2

All primitive data type has a corresponding default value if you declared these variables inside the class but outside the methods. Which of the following data type will NOT have zero (0) as its default value?

Boolean

Given the line of code that uses the ternary operator. int price = isPremiumMember() ? 80 : 100; What should be the return type of the method isPremiumMember()?

Boolean

Match the Java Boolean Operators (Non-Short Circuit Java Operators) with their corresponding Symbols. Boolean OR | | Boolean AND && xOR + NOT !

Boolean OR | Boolean AND & xOR ^ NOT ~

Complete the given snippet below: int a = 100, b = 200; System.out.println(a > b ?______:b); The code should display the larger number between the two variables.

Both- a. a b. b

Given: byte x = 7; byte y = 21; What value would the expression x > y return?

False

In the Modulus operator, the left-hand operand and the right-hand operand values are interchangeable. This means, at all times, switching the values of the left-hand operand and the right-hand operand would always result in the same value.

False

Given the code snippets: byte b = 10; short s = 20; int i = 30; long lo = 40L; float f = 1.1F; char ch = 'a';

Float

Given an integer variable x, match the correct Unary Operator Symbol with their names. Postfix Decrement x-- Prefix Decrement --x Postfix Increment x++ Prefix Increment ++x

Postfix Decrement x-- Prefix Decrement --x Postfix Increment x++ Prefix Increment ++x

Given two boolean variables: boolean a = true; boolean b = false; boolean result = // put code here Which of the options below will assign true to variable result? Select one:

a && !b

Given the code snippet: int foo = 25; switch(foo){ case 25: System.out.println("Awesome!"); break; case 26: System.out.println("Cool!"); break; case 27: System.out.println("Terrific!"); break; default: System.out.println("Wonderful!"); } // end of switch What will be the output?

b. Terrific! c. Cool! d. Awesome!

The Primitive data types can be widened implicitly (automatically), but if it does it follows a certain widening path. If a byte needs to be widen to a double, what is the correct path?

byte--> short-->int-->long-->float-->double

Fill in the blank on the snippet below so that the output will be true. boolean a = false; int b = 5; System.out.println(_______________&& ++b >= 5);

!a

Fill in the correct Assignment Operator so that num1 will have a value of 2. int num1 = 18; int num2 = 4 term-47; num1 %= num2

%=

Given the code snippet below: int x = 36, y = 10; System.out.println(x / y); What is the output when the code was inserted in a working java source code?

3 not- 3.0

Given the code snippet: double num1 = 3.9999; int num2 = (int)num1; What will be the value of num2?

3 not- 3.0

Given the code snippet: int a = 10, b = 20, c = 30; int result = a > b ? a : b > c ? b : c; What will be the value of result?

30

Given the code snippet: int totalAttendees = 10; String result = totalAttendees <= 2 ? "couple" : totalAttendees > 2 && totalAttendees < 5 ? "a few" : totalAttendees <= 5 ? "several" : "many"; What is the value of totalAttendees with the output based on the given ternary expression. Output will be:

30

Given the snippet: int num1 = 5; System.out.println(num1++); What will be the output?

5

Given a snippet: int a = 30, b = 7; System.out.println(a++ % ++b); What will be the output?

6

What is the value of 36 % 10?

6

Given the Java code snippet below: int num1 = 11; int num2 = 7; System.out.println(num1 *= num2); What is the output?

77

Given the Java code snippet below: int num1 = 18; int num2 = 18; System.out.println((num1 /= num2) + 7); What is the output?

8

Given the variables below: int num1 = 25, num2 = 20;num1 %= (num2 /= 5); After execution, which of the following variable values are correct?

? a. num1 = 5 and num2 = 0 d. num1 = 1 and num2 = 4

Which of the following is NOT true about the ternary operator?

The result of the ternary operator should ALWAYS be a String value.

Given: byte x = 24; byte y = 18; The returned value of: x > y is True The returned value of: x < y is False The returned value of: x == y is False

The returned value of: x > y is True The returned value of: x < y is False The returned value of: x == y is False

What is the purpose of Relational Operators?

To compare the values of the numbers and or variables.

Given the Java code snippet below: int num1 = 36; int num2 = 12; System.out.println(num1 /= num2); The output displayed by the program is 3.

True

Given the snippet below: boolean a = false; int b = 5; System.out.println(!a && b++ == 5); What is the output?

True

Given: short x=15; short y=15; What value would the expression x == y return?

True

Java expressions that use Relational Operators return only these two values: true or false.

True

Java has______relational operators that compare two numbers and return a boolean value.

a. ?-not four b.two

What is another way of writing this Java expression? Choose three correct answers. x = x + 1;

all- a. x++; c. ++x d. x += 1;

Given the snippet below, fill in the correct value so that the output will be true. boolean a = false; boolean b = true; System.out.println(a ^b);

b

The Unicode integer value of 'a' is 97 (base 10). Given the code snippet: char ch = 'a'; System.out.println(++ch); What will be the output of the given snippet?

b

Given the snippet: boolean isOpen = true; System.out.print(!!!isOpen); System.out.println(!!isOpen); The output is:

falsetrue

Which of the following choices can a long data type be implicitly promoted to? Choose two.

float double not- byte short

Given the code snippet below: int num = 45; num /= 5; num *= 3; num =- 2; At the end of this code, what is the value of num?

not- 25

What Data Type is apt to store the result of Java Expressions that use Relational Operators?

not- string object


Set pelajaran terkait

11/4 Quiz: EXCLUSIONS, RESTRICTIONS, RIDERS AND PROHIBITED PROVISIONS

View Set

PMP Rita - Chapter 11: Risk Management

View Set

Week 7 Check Your Understanding Assignment PATHO: 370

View Set

Taxes, Retirement, and Other Insurance Concepts

View Set