Java Ch.5-8

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

Type the ending value of z. x = 9.0;z = Math.pow(Math.sqrt(x) + Math.sqrt(x), 2.0);

36.0

What will be the value of z as a result of executing the following code? int x = 5, y = 28; float z; z = (float) (y / x); 5.60 5.6 3.0 5.0

5.0

Goal output: Say "Hello" System.out.print(_____); "Say "Hello"" "Say \"Hello\"" 'Say "Hello"' "Say \\"Hello\\""

"Say \"Hello\""

To output a double in scientific notation with printf, you would use %d %e %f %s

%e

What is the output from the following print statement, assuming int numCount = -5; System.out.printf("%05d", numCount);

-0005

What will be the value of x after the following statement is executed: double x = 3 / (2 * 2); 0 1 3 none of the above

0

What is the output from the following print statement, assuming double pi = 3.1415927; System.out.printf("%09.2f", pi);

000003.14

Match the class to the correct package. 1. Scanner 2. FileInputStream 3.BigDecimal

1. java.util 2. java.io 3. java.math

Type the value of the expression. For any floating-point answer, type answer to tenths. Ex: 8.0, 6.5, or 0.1. For any integer answer, type answer without any decimal point. 3.0 / 2

1.5

What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x = x - y; 75 15 60 135

15

After the following code fragment is executed, what will be printed? int f = 9, g = 8; if (f < g) f = 8; g = 9; System.out.println("" + (f + g)); 16 17 18 88 89 98 99

18

What will be the value of x after the following statement is executed:int x = (3 / 2) * 2; 1 1 2 3 none of the above

2

In the code fragment below, which value will be assigned to discountRate? double a=22, b=24, c=27, d=29, e=31; double discountRate = 0.0; int purchase = 1000; char cust = 'N'; if (purchase > 1000) if (cust == 'Y') discountRate = a; else discountRate = b; else if (purchase > 750) if (cust == 'Y') discountRate = c; else discountRate = d; else discountRate = e;

29.0

Which of the numbered lines below will be executed in the following code? 1 int bonus, sales = 1250; 2 if (sales > 1000) 3 bonus = 100; 4 else if (sales > 750) 5 bonus = 50; 6 else if (sales > 500) 7 bonus = 25; 8 else 9 bonus = 0;

3

Which of the numbered lines in the following code are executed? 1 int ans = 35, x = 50, y = 50; 2 if (x >= y) { 3 ans = x + 10; 4 x = x - y; 5 } 6 else { 7 ans = y + 10; 8 y = y + x; 9 }

3

Type 540,000,000 as a floating-point literal using scientific notation with a single digit before and after the decimal point.

5.4e8

Type the value of the expression given int numItems = 5. For any floating-point answer, type answer to tenths. Ex: 8.0, 6.5, or 0.1. For any integer answer, type answer without any decimal point. (numItems + 10) / 2

7

Which of the numbered lines is executed in the following code? 1 int bonus, sales = 8000; 2 if (sales < 5000) 3 bonus = 200; 4 else if (sales < 7500) 5 bonus = 500; 6 else if (sales < 10000) 7 bonus = 750; 8 else if (sales < 20000) 9 bonus = 1000; 10 else 11 bonus = 1250;

7

After the following code, what is the value of str1? String str1 = "Hello"; str1.concat("world"); Hello Helloworld world none

Hello

What is the output from the following print statement, assuming String profName = "Maxfield"; System.out.printf("%.4s", profName);

Maxf

What will be the values of ans, x, and y after the following statements are executed? int ans = 0, x = 15, y = 25; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

ans = 35, x = 15, y = 40

What is the data type of the following literal:'A'

char

A program must import the InputStream class in order to use System.in. true or false

false

Characters written to System.out are immediately written to a system's standard output. true or false

false

Given userText = "June" userText.charAt(userText.length()) returns 'e'. true or false

false

float is the most commonly-used floating-point type. true or false

false

userStr is "Hello, world!". Character.toLowerCase(userStr.charAt(1)) yields an error because 'e' is already lower case . true or false

false

Write an if statement that sets x to "temperature OK" if the variable y is 18 through 25 (inclusive.)

if ((y >= 18) && (y <= 25)){ x = "temperature OK"; }

Rewrite the following code as exactly as possible, using an if-else-if structure instead of the switch. Assume that the following code was taken from a working program (it was) and don't worry about what comes before or after this section. (I.e. don't worry about declarations, etc.) Your code should do whatever this code does. switch (choice) { case 1: name = "animal"; break; default: System.out.println("Invalid entry. Using default"); case 2: name = "vegetable"; break; case 3: name = "mineral"; }

if (choice == 1) { name = "animal"; } else if (choice == 2) { name = "vegetable"; } else if (choice == 3) { name == "mineral"; } else { System.out.println("Invalid entry. Using default"); name = "vegetable"; }

Assume chr is a char variable and x is an int. Write an if statement that sets x to 5 if the char variable contains an A.

if (chr == 'A'){ x = 5; }

Write an if statement that sets x to 9 if the contents of the String variable lastName is your last name. Write only the if statement.

if (lastName == yourLastName){ x = 9; }

Write an if statement that assigns 65 to y if x not equal to 3? (65 and 3 are literals, x and y are variables.)

if (x != 3){ y = 65; }

Which of the numbered lines will be executed in the following code? 1 int x = 10; 1 int x = 10; 2 switch (x) { 3 case 10: 4 x = x + 15; 5 case 12: 6 x = x - 5; 7 break; 8 default: 9 x = x * 3; 10 } 4 6 9 more than one of the above

more than one of the above

Assume an int named randNum and a random number generator object named randGen exists. Use the one-arg randGen.nextInt() method to assign a random number between 10 (inclusive) and 15 (inclusive) to randNum

randNum = randGen.nextInt(6)+10;

A read from System.in will read bytes from a buffer filled by the operating system. true or false

true

Indicate whether the following is a good variable declaration for the stated purpose, assuming int is usually used for integers, and long is only used when absolutely necessary. The number of days of school per year: int numDaysSchoolYear; True or False?

true

The expression in the ( )s of an if statement must evaluate to 0 or 1 +1 or -1 true or false

true or false

Which of the following expressions means "x is greater than or equal to y"? x>y x => y x <= y x >= y

x >= y


Conjuntos de estudio relacionados

Ch.19 gene mutation and DNA repair McGraw hill assignment

View Set

BUS 503QR Lean Six Sigma Green Belt Exam Review

View Set

CH1: Levels of Structural Organization

View Set

Progressive, Regressive and Proportional Taxes-Financial Literacy

View Set

Mental Health - Ch 25 - Suicide and Non-suicidal

View Set

Review From 1491-1607 ¨Settling of the Western Hemisphere¨

View Set

World Geography Chapter 9-11 South America

View Set

Network+ Ch.6: Wireless Networking

View Set