Java Chapter 2

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

Math.pow(4, 1 / 2) returns __________.

1.0

Which of the following expressions will yield 0.5?

1.0 / 2 (double) 1 / 2 1 / 2.0

What is the result of 45 / 4?

11

If you enter 1 2 3, when you run this program, what will be the output? import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three numbers: "); double number1 = input.nextDouble(); double number2 = input.nextDouble(); double number3 = input.nextDouble(); // Compute averagedouble average = (number1 + number2 + number3) / 3;// Display resultSystem.out.println(average);}}

2.0

Math.pow(4, 1.0 / 2) returns __________.

2.0

What is the value of (double)(5/2)?

2.0

What is the value of (double)5/2?

2.5

The expression 4 + 20 / (3 - 1) * 2 is evaluated to

24

Suppose x is 1. What is x after x += 2?

3

Which of the following expression results in a value 1?

37 % 6

24% 5 is ______

4

What is i printed in the following code? public class Test { public static void main(String[] args) { int j = 0; int i = j++ + j * 5; System.out.println("What is i? " + i); } }

5

What is i printed? public class Test { public static void main(String[] args) { int j = 0; int i = ++j + j * 5; System.out.println("What is i? " + i); } }

6

The expression (int)(76.0252175 * 100) / 100 evaluates to _________.

76

Math.pow(2, 3) returns __________.

8.0

____________ is the Java assignment operator.

=

_____________ is a formal process that seeks to understand the problem and document in detail what the software system needs to do.

Requirements specification

Which of the following is a valid identifier?

$343 & radius

Which of the following statements are the same? (A) x -= x + 4 (B) x = x + 4 - x (C) x = x - (x + 4)

(A) and (C) are the same

Which of the following expression results in 45.37?

(int)(45.378 * 100) / 100.0

-24 % -5 is _____

-4

-24% 5 is _____

-4

-25 % 5 is _____

0

25 % 1 is _____

0

Suppose x is 1. What is x after x -= 1?

0

_____________ seeks to analyze the data flow and to identify the system?s input and output. When you do analysis, it helps to identify what the output is first, and then figure out what input data you need in order to produce the output.

Analysis

To add number to sum, you write (Note: Java is case-sensitive)

D. sum += number; E. sum = sum + number;

The following code fragment reads in two numbers: Scanner input = new Scanner(System.in); int i = input.nextInt(); double d = input.nextDouble(); What is the incorrect way to enter these two numbers?

Enter a numeric value with a decimal point, a space, an integer, and then the Enter key.

Which of the following is a constant, according to Java naming conventions?

MAX_VALUE & COUNT

How do you write 2.5 ^ 3.1 in Java?

Math.pow(2.5, 3.1)

The __________ method returns a raised to the power of b.

Math.pow(a, b)

To obtain the current second, use _________.

System.currentTimeMillis() / 1000 % 60

To obtain the current minute, use _________.

System.currentTimeMillis() / 1000 / 60 % 60

To obtain the current hour in UTC, use _________.

System.currentTimeMillis() / 1000 / 60 / 60 % 24

Analyze the following code. public class Test { public static void main(String[] args) { int month = 09; System.out.println("month is " + month); } }

The program has a syntax error, because 09 is an incorrect literal value.

Analyze the following code: public class Test { public static void main(String[] args) { int n = 10000 * 10000 * 10000; System.out.println("n is " + n); } }

The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program continues to execute because Java does not report errors on overflow.

Every letter in a java keyword is in lowercase?

True

Are the following four statements equivalent?number += 1; number = number + 1; number++; ++number;

Yes

Which of the following is incorrect?

_4544

Which of the following are the same as 1545.534?

all of the above: A. 1.545534e+3 B. 0.1545534e+4 C. 1545534.0e-3 D. 154553.4e-2

The exact output of the following code double area = 3.5; System.out.print("area"); System.out.print(area);

area3.5

Suppose a Scanner object is created as follows, what method do you use to read a real number?Scanner input = new Scanner(System.in);

input.nextDouble();

To improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159.

constants

If you attempt to add an int, a byte, a long, and a double, the result will be a(n) __________ value.

double

To declare a constant MAX_LENGTH inside a method with value 99.98, you write

final double MAX_LENGTH = 99.98;

According to Java naming convention, which of the following names can be variables?

findArea & totalLength

Which of the following is incorrect?

float x = 1.0;

Which of the following assignment statements is incorrect?

i = 1 = j = 1 = k = 1; & i == j == k == 1;

Which of the following are correct ways to declare variables?

int length, width; & int length; int width;

To declare an int variable number with initial value 2, you write

int number = 2;

Which of the following assignment statements is illegal?

int t = (int)false; int t = 4.5;

Which of these data types requires the most amount of memory?

long

the code with natural language mixed with java code

pseudocode

The System.currentTimeMillis() returns ________________ .

the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).

Which of the following are correct names for variables according to Java naming conventions?

radius & FindArea

When assigning a literal to a variable of the byte type, if the literal is too large to be stored as a byte value, it _____________.

receives a compile error

To assign a double variable d to a float variable x, you write

x = (float)d;

To assign a value 1 to variable x, you write

x = 1;

To add a value 1 to variable x, you write

x = x + 1;

What is x after the following statements?int x = 1;x *= x + 1;

x is 2.

What is x after the following statements?int x = 2; int y = 1; x *= y + 1;

x is 4.

What is the output of the following code: double x = 5.5; int y = (int)x; System.out.println("x is " + x + " and y is " + y);

x is 5.5 and y is 5

What is y displayed? public class Test { public static void main(String[] args) { int x = 1; int y = x + x++; System.out.println("y is " + y); } }

y is 2.

What is y displayed in the following code?public class Test { public static void main(String[] args) { int x = 1; int y = x++ + x; System.out.println("y is " + y); } }

y is 3


Set pelajaran terkait

CM checkpoint #5 review (for Quizlet Live)

View Set

EMT Chapter 30 Environmental Emergencies

View Set

Uncertainty and Change - Seminar Quiz

View Set

Chapter 11 - Analysis of Variance

View Set

Science 3.1 Cell division occurs in all organisms

View Set

Anatomy Lecture Final Exam: The Digestive System

View Set

Business management Honors State Test Review 3.00

View Set

Intro to Cybersecurity CIT 171 REVIEW

View Set