Exam 4: Fundamental Data Types

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Which of the following statements about constants in Java are true? I. Although not required, constants are commonly named using uppercase letters II. Only integer values can appear as constants III. A variable can be defined with an initial value, but the reserved word final prevents it from being changed IV. A named constant makes computations that use it clearer

Free
(Multiple Choice)
4.8/5
(32)
Correct Answer:
Verified

C

Assuming that the user inputs a value of 25000 for the pay and 10 for the bonus rate in the following code snippet, what is the output? public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter the pay: "); Double pay = in.nextDouble(); System.out.print("Enter the bonus rate: "); Double bonus = in.nextDouble(); System.out.println("The new pay is " + (pay + pay * (bonus / 100.0))); }

Free
(Multiple Choice)
4.9/5
(32)
Correct Answer:
Verified

C

The typical ranges for integers may seem strange but are derived from

Free
(Multiple Choice)
4.7/5
(38)
Correct Answer:
Verified

D

Which one of the following statements displays the output as 54321.00?

(Multiple Choice)
4.9/5
(35)

What is the value inside the value variable at the end of the given code snippet? public static void main(String[] args) { Int value = 3; Value = value - 2 * value; Value++; }

(Multiple Choice)
4.8/5
(36)

What is the output of the following code snippet? public static void main(String[] args) { Double a; A = Math.sqrt(9.0) + Math.sqrt(16.0); System.out.println(a); }

(Multiple Choice)
4.8/5
(41)

What does the following statement sequence print? String str = "Hello"; Int n = str.length(); String mystery = str.substring(0, 1) + str.substring(n - 2, n + 1); System.out.println(mystery);

(Multiple Choice)
4.9/5
(49)

What is wrong with the following code snippet? Int price; Price = 9.42;

(Multiple Choice)
4.8/5
(42)

What will be the value inside the variables x and y after the given set of assignments? Int x = 20; Int y = 10; X = (x - y) * 2; Y = x / 2;

(Multiple Choice)
4.9/5
(40)

Which one of the following is a correct representation of the given mathematical expression in Java? a + b 2

(Multiple Choice)
4.7/5
(36)

Assume the variable str has been declared to be a String that has at least one character. Which is the following represents the last character in str?

(Multiple Choice)
4.9/5
(33)

Which of the given System.out.print statements generates the following output? ABCDE"\

(Multiple Choice)
4.9/5
(26)

What is the output of the following code snippet? public static void main(String[] args) { Int num1 = 10; Int num2 = 5; Int num3 = 200; Num3 = num3 % (num1 * num2); System.out.println(num3); }

(Multiple Choice)
4.9/5
(29)

Which statement is true?

(Multiple Choice)
4.8/5
(39)

What will be the value inside the variables a and b after the given set of assignments? Int a = 20; Int b = 10; A = (a +B) / 2; b = a; A++;

(Multiple Choice)
4.8/5
(43)

Assume the following variable has been declared and given a value as shown: String str = "0123456789"; Which is the value of str.length()?

(Multiple Choice)
4.8/5
(27)

What (if any) type of error occurs with the following code if the user input is ABC? public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); String str = in.next(); Int count = Integer.parseInt(str); System.out.println("Input is " + count); }

(Multiple Choice)
4.9/5
(35)

What will be printed by the statements below? Int x = 100; Int y = -12; System.out.print ("Sum is " + x + y);

(Multiple Choice)
4.8/5
(38)

Which of the following statements is correct about constants?

(Multiple Choice)
4.9/5
(36)

Suppose a phone number, stored as a ten-character string (of digits only) called phoneNumber must be converted into a string that has parentheses around the area code. Which statement below will do that?

(Multiple Choice)
4.9/5
(37)
Showing 1 - 20 of 125
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)