AP COMPUTER SCIENCE A UNIT 1 EXAM

4.0(1)
studied byStudied by 12 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

20 Terms

1
New cards

Assuming that scan is a properly initialized Scanner variable, which of the following correctly inputs a String?

String val = scan.nextLine();

2
New cards

Consider the following code:
int x = -3;
x--;
System.out.println(x);

What is output?

-4

3
New cards

Which of the following data types would be most appropriate to use when recording whether a switch is in the "on" or "off" position?

boolean

4
New cards

Which of the following is NOT a primitive data type?

String

5
New cards

What is output by the following code?
int a = 91;
System.out.println(a / 2);

45

6
New cards

Which of the following is a legal variable name in Java?

ans

7
New cards

What is (6 % 2) * 7?

0

8
New cards

Which of the following would properly create A and B as integer variables?

int A;
int B;

9
New cards

Which of the following correctly stores the word umbrella in a variable called stuff?

String stuff = "umbrella";

10
New cards

Consider the following code:
int c = 3 - 37 % 2;
System.out.println(c);

What is output?

2

11
New cards

Consider the following code:
int x = 9;
int y = 6;
System.out.println( (x*y)/x );

What is output?

6

12
New cards

Consider the following variable declaration:
double y = 52;

Does a cast need to be added so this code will compile and run successfully? ______. If so, what should be typed for this cast? _______

no, nothing

13
New cards

For which of the following would modular division be LEAST likely to be useful?

converting decimals to whole numbers

14
New cards

The following code is intended to input three integers and print the average. What is a potential problem with the code as written?

System.out.println("Please enter three integers: ");
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
System.out.println("The average is: " + (a + b + c) / 3);

It needs a cast so that the decimal portion will be shown.

15
New cards

What is output by the following code?

int val = -2;
val++;
val--;
val++;
val++;
val++;
val--;
val++;
System.out.println(val);

1

16
New cards

What is the value of w after executing this segment of code?

int w = 18;
w += 18;

36

17
New cards

When might you encounter a problem with integer overflow?

When trying to store an integer which is too big to be stored in an int variable

18
New cards

There are two integer variables in our program, minutes and hours, which represents time. If in the program, we increase the number of minutes by one, which of the following lines of code will correctly update hour and minutes?

hours = hours + minutes / 60;
minutes = minutes % 60;

19
New cards

Correct the following code so that q stores the nearest integer below 82.3847.

int q = 82.3847;

int q = (int) 82.3847;

20
New cards

Which of the following will print the ones column of an integer stored in x?

System.out.print(x % 10);