AP COMPUTER SCIENCE A UNIT 1 EXAM

studied byStudied by 11 people
4.0(1)
Get a hint
Hint

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

1 / 19

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

20 Terms

1

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

String val = scan.nextLine();

New cards
2

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

What is output?

-4

New cards
3

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

New cards
4

Which of the following is NOT a primitive data type?

String

New cards
5

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

45

New cards
6

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

ans

New cards
7

What is (6 % 2) * 7?

0

New cards
8

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

int A;
int B;

New cards
9

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

String stuff = "umbrella";

New cards
10

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

What is output?

2

New cards
11

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

What is output?

6

New cards
12

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

New cards
13

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

converting decimals to whole numbers

New cards
14

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.

New cards
15

What is output by the following code?

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

1

New cards
16

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

int w = 18;
w += 18;

36

New cards
17

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

New cards
18

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;

New cards
19

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

int q = 82.3847;

int q = (int) 82.3847;

New cards
20

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

System.out.print(x % 10);

New cards

Explore top notes

note Note
studied byStudied by 45 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 92 people
Updated ... ago
4.9 Stars(7)
note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 22 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 23 people
Updated ... ago
5.0 Stars(1)

Explore top flashcards

flashcards Flashcard37 terms
studied byStudied by 61 people
Updated ... ago
5.0 Stars(3)
flashcards Flashcard94 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard67 terms
studied byStudied by 27 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard20 terms
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard25 terms
studied byStudied by 71 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard39 terms
studied byStudied by 19 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard24 terms
studied byStudied by 16 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard34 terms
studied byStudied by 48 people
Updated ... ago
5.0 Stars(1)