234 Exam

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

When you're using an IDE's debugger and execution reaches a breakpoint, you can click

the Step Into button to execute the current statement and move to the next statement

Which of the following is not a binary operator?

++

What is the value of routeNumber after the following statement is executed if the value of zipCode is 93705?switch (zipCode) {case 93705:case 93706: routeNumber = 1; break;case 93710:case 93720: routeNumber = 2; break;default: routeNumber = 0; break;}

1

What is the range of values that x can hold after this statement is executed?double x = Math.random() * 10 + 100;

100 <= x < 110

If int variable x = 100, float variable y = 1.587F, and double variable z = 4.8, what does the following expression return?x + Math.round(y) + (int) z

106

Assume that before the following code is executed, the value of totalOne is 6.728, the value of totalTwo is 116, and both are BigDecimal objects. What is the value of totalFinal after the code is executed?totalOne = totalOne.setScale(2, RoundingMode.HALF_UP);BigDecimal totalFinal = totalTwo.add(totalOne);

122.73

If the int variables a = 5, b = 2, and c = 10, what is the value of c after the following statement is executed?c = c + a * b - 5;

15

How many lines are printed on the console when the following for loop is executed?for (int j = 10; j < 40; j *= 2) {System.out.println(j);}

2

int limit = 0;for (int i = 10; i >= limit; i -= 2) { for (int j = i; j <= 1; j++) { System.out.println("In inner for loop"); } System.out.println("In outer for loop");} (Refer to code example 4-1.) How many times does "In inner for loop" print to the console?

2

How many lines are printed on the console when the following for loops are executed?for (int i = 1; i < 5; i += 2) {for (int j = 0; j < i; j++) { System.out.println(j); }}

4

If number is 20, what is printed to the console after this code is executed?for (int i = 3; i <= number; i += 2) {if (number % i == 0) { System.out.println(i); if (i == number) { System.out.println("special"); } break;}}

5

If the double variables x = 2.5 and y = 4.0, what is the value of z after this statement is executed?int z = (int) x + (int) y;

6

If the variable named input is 755, what is the value of r after these statements are executed?NumberFormat n = NumberFormat.getNumberInstance();n.setMinimumFractionDigits(3);String r = n.format(input);

755.000

Assume that the variable named entry has a starting value of 9 and number has a value of 3. What is the value of entry after the following statements are executed?if ((entry > 9) || (entry/number == 3)) { entry--;} else if (entry == 9) { entry++;} else { entry = 3;}

8

Assume that the variable named entry has a starting value of 9 and number has a value of 3. What is the value of entry after the following statements are executed?if ((entry > 9) || (entry/number == 3)) {entry--;} else if (entry == 9) {entry++;} else { entry = 3;}

8

How many lines are printed on the console when the following for loop is executed?for (int i = 2; i < 10; i++) { System.out.println(i);}

8

How many lines are printed on the console when the following for loop is executed?for (int i = 2; i < 10; i++) {System.out.println(i);}

8

The has methods of the Scanner class let you

A and b only

Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:818) at java.util.Scanner.next(Scanner.java:1420) at java.util.Scanner.nextDouble(Scanner.java:2324) at FutureValueApp.main(FutureValueApp.java:17) (Refer to output example 5-1.) What is this output called?

A stack trace

To determine the cause of an unhandled exception, you can

All of the above

When a statement within a try block causes an exception, the remaining statements in the try block

Aren't executed

Which of the following statements creates a BigDecimal variable named decimalSubtotal from a double variable named subtotal, making sure that conversion problems are avoided.

BigDecimal decimalSubtotal = new BigDecimal(Double.toString(subtotal));

Unlike an if/else statement, a switch statement

Can't perform an operation based on the result of a Boolean expression

Unlike a variable, a constant can't

Change in value as an application runs

Which of the following statements do you use to jump to the top of a loop from within loop?

Continue

Which of the following is a valid class name?

CustomerMaintApp

import java.util.Scanner;import java.text.NumberFormat;public class WeightConverter { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String prompt = "Enter weight in lbs: "; boolean isValid = false; double weightInPounds = 0.0; while (!isValid) { weightInPounds = getDouble(sc, prompt); if (weightInPounds > 0) { isValid = true; } else { System.out.println("Weight must be greater than 0."); } } double weightInKilos = weightInPounds / 2.2; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); String message = weightInPounds + " lbs\nequals\n" + nf.format(weightInKilos) + " kgs\n"; System.out.print(message); } public static double getDouble(Scanner sc, String prompt) { double d = 0.0; boolean isValid = false; while (!isValid) { System.out.print(prompt); if (sc.hasNextDouble()) { d = sc.nextDouble(); isValid = true; } else { System.out.println ("Error! Invalid decimal value. Try again."); } sc.nextLine(); } return d; }}(Refer to code example 5-1.) If the user enters -1 at the first console prompt, what does the code do?

Display an error message from the main() method

Based on the naming recommendations in the book, which of the following is a good identifier for a variable that will be used to hold an employee's phone number?

EmployeePhoneNumber

Consider the following condition. It will be true when(!endProgram.equalsIgnoreCase("n")) The value of endProgram doesn't equal "n" or "N" Assume the user enters "X" at the first console prompt when the following code is executed. The value of numOfEntries will beString option = "";int numOfEntries = 0;do { numOfEntries++; System.out.print("Enter 'C' to continue."); option = sc.next();}while (option.equalsIgnoreCase("C"));

Equal to one

What is the third line printed to the console in the code that follows?int items = 3;for (int i = 1; i <= items; i++) { int result = 1; for (int j = i; j >= 1; j--) { result *= j; } System.out.println("Factorial " + i + " = " + result);}

Factorial 3 = 6

What is the third line printed to the console in the code that follows?int items = 3;for (int i = 1; i <= items; i++) {int result = 1;int j = i;while (j >= 1) { result *= j; j--;}System.out.println("Factorial " + i + " = " + result);}

Factorial 3 = 6

The goal of testing is to

Find all errors in the application

Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:818) at java.util.Scanner.next(Scanner.java:1420) at java.util.Scanner.nextDouble(Scanner.java:2324) at FutureValueApp.main(FutureValueApp.java:17) (Refer to output example 5-1.) What is the order of method calls?

FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor

Which of the values below will not be printed to the console when this code is executed?for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { if (i == j) { continue; } System.out.println("i = " + i + " j = " + j); }}

I = 1 j =1

What does debugging an application entail?

Identifying and fixing any bugs.

Which of the following statements calculates the change in sales between two double variables named this YTDSales and lastYTDSales, rounds the result to an integer, and stores it in an integer in an int variable named salesChange?

Int salesChange = math.round(thisYTDSales - lastYTDSales);

Which of the following statements creates an Integer object named countObject from an int variable named count?

Integer countObject = new Integer(count);

import java.util.Scanner;public class InvoiceApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equals("y")) { System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); double salesTax = subtotal * .0875; double invoiceTotal = subtotal + salesTax; String message = "Subtotal = " + subtotal + "\n" + " Sales tax = " + salesTax + "\n" + "Invoice total = " + invoiceTotal + "\n\n" System.out.println(message); System.out.print("Continue? Enter y or n: "); choice = sc.next(); } }} Refer to code example 2-1.) The name of the file that contains this source code must be

InvoiceApp.java

Which of the following is not a feature of using an Installer program to deploy an application?

It automatically updates the application when a new version is available.

Which of the following is a feature of using an executable JAR file to deploy an application?

It has no significant security restrictions.

Which of the following is not a feature of using Java Web Start to deploy an application?

It has no significant security restrictions.

If the variable named percent is 0.0755, what is the value of p after this statement is executed?

String p = NumberFormat.getPercentInstance().format(percent); 8%

What is the main reason for coding a method to validate a specific type of entry?

It saves you from writing variations of the same code again and again to check multiple data entries.

Which of the following is not true of using a IDE to develop Java programs?

Its harder to detect syntax errors

Which of the following statements converts a double variable named subtotal to a String object named subtotalString?

String subtotalString = Double.toString(subtotal);

Explicit casts must be used to perform

Narrowing conversions

In Java, exceptions are

Objects

According to standard naming conventions, which of the following is a typical class name?

Product

An error that occurs after an application is running is known as a

Runtime error

What must you do if you code an infinite loop in an application?

Stop the application to end the loop

Which of the following statements prints a variable named total to the console, followed by a new line character?

System.out.println(total);

Consider the code that follows. What does it do?String value = "2";boolean tryAgain = true;while (tryAgain == true) { try { int num = Integer.parseInt(value); tryAgain = false; } System.out.println("Valid integer"); catch(NumberFormatException nfe) { System.out.println("Invalid integer"); System.out.print("Enter an integer"); value = sc.next }}

The code doesn't compile

What happens when a logical error occurs?

The results of the application will be inaccurate.

What does the following statement do if userNumber has an integer value of 14 and userEntry has a string value of "two"?userNumber = Integer.parseInt(userEntry);

Throws an exception

Which of the following is not a benefit of a typical IDE for Java?

Your code compiles and runs faster

You should validate user entries rather than catch and handle exceptions caused by invalid entries whenever possible because

Your code will run faster

You can use a Scanner object to:

get the next token in an input line

As you develop a Java program, you can use an IDE to

all of the above

Which of the following can you assign to a String variable?

all of the above

You can use the Double class to

all of the above

Using the BigDecimal class, you can

avoid rounding errors that may occur otherwise in business applications

Which of these data types are used to store true/false values?

boolean

Which of the following statements do you use to jump to the end of a loop from within the loop?

break

If the int variables a = 5, b = 2, and c = 10, what is the value of c after the following statement is executed?

c = c + a * b - 5; 15

Block scope means that a variable

can't be used outside of the set of braces that it's declared in

Unlike a variable, a constant can't

change in value as an application runs

Which of the following can you not use the Java API documentation to research?

debuggers

Which of the following statements converts a String object named subtotalString to a double variable named subtotal?

double subtotal = Double.parseDouble(subtotalString);

Which of these data types are used to store numbers with decimal positions?

float

Which of the following formats can you not apply using the NumberFormat class?

fraction

Which of the values below will not be printed to the console when this code is executed?for (int i = 0; i < 3; i++) {for (int j = 0; j < 2; j++) { if (i == j) { continue; } System.out.println("i = " + i + " j = " + j);}}

i = 1 j = 1

Which of the following statements makes all of the classes in the java.io package available to a Java application?

import java.io.*;

You use an escape sequence to

include a special character in a string

Which of the following statements uses a compound assignment operator?

index += 1;

If the value of the int variable named quantity is 5, what is the value of total after this statement is executed?

int total = quantity++; 5

To refer to a Java class from an application without qualification, you need to import the class unless that class

is stored in a package that has already been imported

The extension for a Java source file is

java

An IDE typically stores all of the files for an application in a

project

If you use a short-circuit operator to combine two expressions

the second expression is evaluated only if it can affect the result

A syntax error occurs when

there's a syntax error in a Java statement


Set pelajaran terkait

Genetics, PEDS GENETICS AND METABOLISM

View Set

Bacteriostatic Inhibitors of Protein Synthesis and Aminoglycosides

View Set

`2. Freedom of Information Act (FOIA)

View Set