CSC 151 Chapter 2

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/49

flashcard set

Earn XP

Description and Tags

JAVA PROGRAMMING

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

24 % 5 is ________

4

2
New cards

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

3
New cards

Which of the following is a valid identifier? Please select all that apply.

radius & $343

4
New cards

According to Java naming convention, which of the following names can be variables? Please select all that apply.

findArea & totalLength

5
New cards

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

x = (float)d;

6
New cards

Are the following four statements equivalent?

 number += 1;

 number = number + 1;

 number++;

 ++number;

Yes

7
New cards

Which of the following expression results in 45.37?

(int)(45.378 * 100) / 100.0

8
New cards

What is x after the following statements?

int x = 2;

int y = 1;

x *= y + 1;

x is 4

9
New cards

To add number to sum, you write ________. (Note: Java is case-sensitive) Please select all that apply.

sum += number;

10
New cards

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

0

11
New cards

25 % 1 is ________

0

12
New cards

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

double

13
New cards

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

76

14
New cards

-25 % 5 is ________

0

15
New cards

Which of the following are correct names for variables according to Java naming conventions? Please select all that apply.

radius & findArea

16
New cards

Which of the following assignment statements is incorrect? Please select all that apply.

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

i == j == k == 1;

17
New cards

Which of the following is incorrect?

float x = 1.0;

18
New cards

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

3

19
New cards

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

final double MAX_LENGTH = 99.98;

20
New cards

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

2.5

21
New cards

The System.currentTimeMillis() returns ________.

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

22
New cards

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

23
New cards

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

24
New cards

Which of the following is a constant, according to Java naming conventions? Please select all that apply.

COUNT

MAX_VALUE

25
New cards

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

24

26
New cards

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

long

27
New cards

-24 % 5 is ________

-4

28
New cards

Which of the following expression results in a value 1?

37 % 6

29
New cards

Which of the following expressions will yield 0.5? Please select all that apply.

1.0 / 2

1 / 2.0

(double) 1 / 2

30
New cards

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

31
New cards

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 average

 double average = (number1 + number2 + number3) / 3;

 // Display result

 System.out.println(average);

 }

}

2.0

32
New cards

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

2.0

33
New cards

What is the exact output of the following code?

 double area = 3.5;

 System.out.print("area");

 System.out.print(area);

area3.5

34
New cards

The following code fragment reads in two numbers. What is the incorrect way to enter these two numbers?

Scanner input = new Scanner(System.in);

int i = input.nextInt();

double d = input.nextDouble();

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

35
New cards

How do you write 2.5 ^ 3.1 in Java?

Math.pow(2.5, 3.1)

36
New cards

________ is the Java assignment operator.

=

37
New cards

To improve readability and maintainability, you should declare a ________ for PI instead of using literal values such as 3.14159.

constant

38
New cards

Which of the following are correct ways to declare variables? Please select all that apply.

int length, width;

int length; int width;

39
New cards

-24 % -5 is ________

-4

40
New cards

True or False? Every letter in a Java keyword is in lowercase.

True

41
New cards

To assign a value 1 to variable x, you write ________.

x = 1;

42
New cards

________ is the code with natural language mixed with Java code.

Pseudocode

43
New cards

To add a value 1 to variable x, you write ________. Please select all that apply.

x = x + 1;

x = 1 + x;

x += 1;

44
New cards

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

45
New cards

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

46
New cards

What is the result of 45 / 4?

11

47
New cards

What is x after the following statements?

int x = 1;

x *= x + 1;

x is 2

48
New cards

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.

49
New cards

To obtain the current second, use ________.

System.currentTimeMillis() / 1000 % 60

50
New cards

Which of the following assignment statements is illegal?

int t = 4.5;