AP Computer Science Project Stem Chp. 1

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

Which of the following would Java interpret as being a String?

"Hello World"

Consider the following code: int x = -5; x++; System.out.println(x); What is output?

-4

What number does the program print when compiled and run?

-9223372036854775808

What is 61 % 4?

1

What is (19 % 7) * 2?

10

To find the last two digits of a number you MOD by _______. (for example the last two digits of 7346 is 46)

100

What does x equal after the following code has been executed? int x = 13; x--;

12

Consider the following code: int x = 10; int y = 3; System.out.println((x * y) / x ); What is output?

3

To tell if a number is divisible by 3, MOD by ______.

3

What is output by the following code? int num = 0; num++; num++; num++; num++; num--; num++; num--; num--; num++; System.out.println(num);

3

What is printed by the following code? int j = 33; j %= 6; System.out.println(j);

3

What is the output when the following code is executed? int a = 93; double x = 89.86732; System.out.println(a / 3);

31

What does x equal after the following code has been executed? int x = 16; x = x / 3;

5

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

5

What is 13 % 7?

6

What is printed when the following code has been executed? int x = 13; int y = 6; System.out.println((2 * x + y) % x);

6

Which of the following expressions in Java is equal to 1?

7 % 3

What is the output when the following code is executed? int a = 93; double x = 89.86732; System.out.println((int) x);

89

Consider the following code: int c = 10 - 55 % 2; System.out.println(c); What is output?

9

Long is a data type that is ... longer... than an integer. It still is able to store whole numbers, but reserves a larger space in memory so that it can store a larger value. What is the largest value you can store in a variable that has the long data type?

9,223,372,036,854,775,807

What is x equal to after the following code has been executed: double x = 2.0; double y = 3.5; x = x + 2 * y;

9.0

What is the value of num after executing this segment of code? int num = 21; num += 72;

93

For which of the following would modular division be useful?

All of the choices are correct

What will happen if the computer fails to compile your code?

An error message will be displayed

What are Strings?

Anything that is not used for numerical calculations that can contain any kind of symbol (letters, numbers, and special characters.)

Which of the following is not an example of primitive data types?

Arrays

What data type should you use to hold whether a person passed or failed a class?

Boolean

Consider the following code segment. System.out.print("Ready"); // Line 1 System.out.print("Set"); // Line 2 System.out.print("Go!"); // Line 3 The code segment is intended to produce the following output but may not work as intended. Ready Set Go! Which change, if any, can be made so that the code segment produces the intended output?

Changing print to println in lines 1 and 2

________ is the process of finding and eliminating errors in code.

Debugging

Consider the following code segment. System.out.println(hello); // Line 1 System.out.print(world); // Line 2 The code segment is intended to produce the following output but does not work as intended. hello world Which of the following changes can be made so that the code segment produces the intended output?

Enclosing hello in line 1 and world in line 2 in quotation marks

Consider the following code segment. System.out.print("Hello!"); System.out.println("How "); System.out.print("are "); System.out.print("you?"); What is printed as a result of executing the code segment?

Hello!How are you?

Each of the following code segments is intended to print the word Hello. Which of the following code segments works as intended? System.out.print("Hello"); System.out.print(Hello); System.out.print(He); System.out.print(llo);

I only

Which of the following is NOT a valid string in Java?

In Java, these are all valid strings.

The following code is intended to input two integers and print the average. What is a potential problem with the code as written? System.out.println("Please enter two integers: "); int a = scan.nextInt(); int b = scan.nextInt(); System.out.println("The average is: " + (a + b) / 2);

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

Which of the following correctly describes the difference between reference data types and primitive data types?

Primitive data types are stored directly in a variable, while reference data type variables store a memory reference to where the data is stored.

What does a Scanner allow us to do?

Scanner allows us to take user input and incorporate it into our programs

What is wrong with the following code? Scanner input = new Scanner(System.in); String s = nextLine();

Should be: String s = input.nextLine();

What is the name for the type of data that consists of characters enclosed in double quotes, such as "Hello world!"?

String

Which of the following is not a primitive data type?

String

Which of the following correctly stores the word Ford in a variable called car?

String car = "Ford";

To declare a String variable name and set it equal to "Lillian" you would type:

String name = "Lillian";

Different data types can store different amounts of data. In the options below, which has the data types listed in order, from largest to smallest?

String, double, int, boolean

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

System.out.print(x / 10 % 10);

Suppose the variable "greeting" is used to store a String below: String greeting = "Hello there,"; Which of the following will print "Hello there, user"?

System.out.println(greeting + " user");

Consider the following code segment: /* data type 1 */ x = 0.5; /* data type 2 */ y = true; Which of the following best describes the data types that should be used to replace/* data type 1 */ and /* data type 2 */ so that the code segment compiles without error?

The variable x should be declared as a double and the variable y should be declared as a boolean.

Which of the following is true about numeric casts in Java?

There is a chance that you lose data when you convert from a larger data type to a smaller data type.

An int is smaller in memory than a double?

True

Consider the following code segment. System.out.println("W"); System.out.println("X"); System.out.print("Y"); System.out.print("Z"); What is printed as a result of executing the code segment?

W X YZ

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

What is wrong with the following code? String x; System.out.println(x);

You cannot print the string without first assigning a value

Which of the following data types would be most appropriate to use when recording the answer to a yes or no question?

boolean

Consider the following code segment. System.out.print("cat "); System.out.println("dog "); System.out.println("horse "); System.out.print("cow "); What is printed as a result of executing the code segment?

cat dog horse cow

If you are owed $0.73 in change, which programming statement below would tell you how many quarters you should get? Assume that change is an int variable that stores the number of cents owed (73 in this case).

change % 25

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

days = days + hours / 24; hours = hours % 24;

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

double A; double B;

Executing which of the following lines of code would cause widening conversions to take place?

double a = (double) 23 / 6;

Which line of code properly casts a double to an integer?

double n = (int) 3.14;

Which statement correctly declares a variable that can store a temperature rounded to the nearest tenth of a degree?

double patientTemp;

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

double val = scan.nextDouble();

Assume the following has been typed in: Scanner scan = new Scanner(System.in); Which line of code declares a double y and sets it equal to input from the user?

double y = scan.nextDouble();

Which line of code declares a double variable z and sets it equal to 3.5?

double z = 3.5;

Scanner scan = new Scanner(System.in); String favoriteMeal; System.out.println("Enter your favorite meal for dinner: "); /* missing line */ Which of the following should go in the place of /* missing line */ to get this input from the user and store it in the variable favoriteMeal?

favoriteMeal = scan.nextLine();

Suppose we had declared a String variable called greetString in a program. Which of the following lines would assign this variable to contain the String "Greetings! Nice to meet you"?

greetString = "Greetings! Nice to meet you";

Correct the following code so that p stores the nearest integer below 43.92. int p = 43.92;

int p = (int) 43.92;

A teacher determines student percentages in a course as the points a student earns divided by the total points available in the grading period. Points are awarded only in whole number increments, but student percentages are to be stored as decimals. The following code segment appears in a program used to compute student percentages. Points that a student earns are stored in pointsEarned, the total points available in the grading period are stored in totalPoints, and the student percentage is stored in percentage. int pointsEarned; /* missing code */ Which of the following is most appropriate to replace /* missing code */ in the program?

int totalPoints;double percentage;

Which line of code correctly declares and initializes the variable x to a value of 3?

int x = 3;

Consider the following program which is intended to get the amount of time (in seconds) it took someone to do one of their chores and then converts it to minutes and seconds. Scanner scan = new Scanner(System.in); int m = 0; int s; System.out.print("How many seconds did it take you to do one of your chores? "); s = scan.nextInt(); /* missing code */ System.out.println("It took you " + m + " minutes and " + s + " seconds."); Which of the following could replace the missing code so that it all works as intended?

m = s / 60; s = s % 60;

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

nameOne

Consider the following variable declaration: double number = 23; 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

What will be displayed if the following Java code segment is run? System.out.print("one "); System.out.println("two "); System.out.print("three ");

one two three

What will be printed on the screen when the following code runs? String str1 = "one"; String str2 = "nine"; System.out.print(str1 + str2);

onenine

To output: Hello There You would need to use: System.out._____ ("Hello");System.out.print("There");

println

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

value

Consider the following code segment. int x; int y; x = 3; y = /* missing expression */; x = 1 + 2 * y; System.out.print(x); System.out.println(y); Which of the following can be used as a replacement for /* missing expression */ so that the code segment prints 94 ?

x + 1


Set pelajaran terkait

Assemblies and the Global Assembly Cache

View Set

pediatrics week week 13 chapters 22,26,and 28

View Set

CHM Exam 4 (Chapter 3) Study Guide

View Set

POLS 2305 - American Gov - Chapter 12 Political Parties

View Set

Life Insurance Premiums, Proceeds and Beneficiaries

View Set