Filters
Question type

Study Flashcards

The first step in problem solving is


A) To write the expression that calculates the answer
B) To understand the problem and its inputs and outputs
C) To do examples by hand that confirm the solution will work
D) To write Java code that can be executed and tested

E) C) and D)
F) A) and B)

Correct Answer

verifed

verified

What are the values of num1 and num2 after this snippet executes? Double num1 = 4.20; Double num2 = num1 * 10 + 5.0;


A) num1 = 4.20 and num2 = 63.0
B) num1 = 4.20 and num2 = 47.0
C) num1 = 42.0 and num2 = 42.0
D) num1 = 42.0 and num2 = 47.0

E) A) and B)
F) All of the above

Correct Answer

verifed

verified

Which of the following options is valid with reference to the code snippet? Public static void main(String[] args) { Double d = 45.326; Double r = d % 9.0; System.out.println(r) ; }


A) The value inside the variable r will be 0.326
B) The value inside the variable r will be 5.036
C) Variable r has to be defined as an integer because the % operator always returns an integer
D) The initialization of variable r is wrong, because the % operator expects integer values as operands

E) All of the above
F) A) and D)

Correct Answer

verifed

verified

How do you compute the length of the string str?


A) length(str)
B) length.str
C) str.length
D) str.length()

E) A) and C)
F) A) and B)

Correct Answer

verifed

verified

Which one of the following statements gives the absolute value of the floating-point number x = -25.50?


A) abs(x) ;
B) Math.abs(x) ;
C) x.abs() ;
D) x.absolute() ;

E) None of the above
F) A) and D)

Correct Answer

verifed

verified

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) ; }


A) Compile-time error
B) Run-time error
C) Overflow error
D) Illegal expression

E) C) and D)
F) A) and C)

Correct Answer

verifed

verified

What is wrong with the following code snippet? Int size = 42; Cost = 9.99; System.out.println("size = " + size) ; System.out.println(" cost = " + cost) ;


A) The code snippet uses a variable that has not yet been initialized.
B) The code snippet uses a variable that has not been declared.
C) The code snippet attempts to assign a decimal value to an integer variable.
D) The code snippet attempts to assign an integer value to a decimal variable.

E) B) and C)
F) A) and D)

Correct Answer

verifed

verified

Given the definition final double PI = 3.14159; which of the following is the Java equivalent of the mathematical expression c = π\pi . radius2


A) c = PI * (radius * 2) ;
B) c = PI * Math.pow(2, radius) ;
C) c = PI * Math.pow(radius, 2) ;
D) c = Math.pow(PI * radius, 2) ;

E) C) and D)
F) A) and D)

Correct Answer

verifed

verified

Which one of the following reserved words is used in Java to represent a value without a fractional part?


A) integer
B) int
C) Int
D) Float

E) B) and C)
F) A) and D)

Correct Answer

verifed

verified

What does the following statement sequence print? Final String str = "Java"; Str += " is powerful"; System.out.println(str) ;


A) Java is powerful
B) Java + is powerful
C) is powerful
D) Nothing; compile-time error

E) A) and C)
F) A) and B)

Correct Answer

verifed

verified

At what point in the problem-solving process should one write pseudocode?


A) After writing Java code, as a way to summarize the code's algorithm
B) Before writing Java code, as a guide for a general solution
C) After defining Java variables so that the pseudocode and data types make sense
D) Before working out examples by hand in order to guide those examples

E) C) and D)
F) B) and D)

Correct Answer

verifed

verified

What is the meaning of x = 0; in Java?


A) It checks whether x equals 0.
B) It sets the variable x to zero.
C) It defines a variable named x and initializes it with 0.
D) It is a syntax error because x is not always 0.

E) B) and C)
F) A) and D)

Correct Answer

verifed

verified

Which of the given statements generates the following output? \\\"///


A) System.out.println("\\\"///") ;
B) System.out.println("\\\\\\\"///") ;
C) System.out.println("\\\\\\""//////") ;
D) system.out.println("\\\"///") ;

E) A) and B)
F) B) and C)

Correct Answer

verifed

verified

Assuming that the user inputs a value of 25 for the price and 10 for the discount 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 price: ") ; Double price = in.nextDouble() ; System.out.print("Enter the discount rate: ") ; Double discount = in.nextDouble() ; System.out.println("The new price is " + Price - price * (discount / 100.0) ) ; }


A) The new price is 25
B) The new price is 15
C) The new price is 22.5
D) The new price is 20.0

E) A) and D)
F) A) and C)

Correct Answer

verifed

verified

Which operator is used to concatenate two or more strings?


A) +
B) %
C) &
D) ^

E) C) and D)
F) A) and B)

Correct Answer

verifed

verified

Which one of the following statements displays the output as (1.23e+02) ?


A) System.out.printf("%(5.2e", -123.0) ;
B) System.out.printf("%5.2e", -123.0) ;
C) System.out.printf("^5.2e", -123.0) ;
D) System.out.printf("%5.2E", -123.0) ;

E) C) and D)
F) B) and D)

Correct Answer

verifed

verified

What is the output of the following code snippet? Int counter = 0; Counter++; System.out.print("The initial value of the counter is ") ; System.out.println(count) ;


A) The initial value of the counter is 0
B) The initial value of the counter is 1
C) The code will not compile
D) The initial value of the counter is

E) C) and D)
F) A) and D)

Correct Answer

verifed

verified

Consider the following division statements: I. 22 / 7 II. 22.0 / 7 III. 22 / 7.0 Which of the following is correct?


A) All three statements will return an integer value.
B) Only I will return an integer value.
C) Only I, II will return an integer value.
D) Only I and III will return an integer value.

E) A) and B)
F) A) and C)

Correct Answer

verifed

verified

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


A) System.out.println("ABCDE\"\\") ;
B) System.out.println("ABCDE"\") ;
C) System.out.println("ABCDE"\) ;
D) System.out.println("ABCDE\"\") ;

E) A) and D)
F) B) and C)

Correct Answer

verifed

verified

Consider the following Java variable names: I. 1stInstance II. basicInt% III. empName_ IV. addressLine1 V. DISCOUNT Which of the following options is correct?


A) Only IV is a valid Java variable name.
B) Only I and IV are valid Java variable names.
C) Only I, IV, and V are valid Java variable names.
D) Only III, IV, and V are valid Java variable names.

E) All of the above
F) A) and D)

Correct Answer

verifed

verified

Showing 81 - 100 of 103

Related Exams

Show Answer