Unit 1 Edhesive AP Computer Science

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

________ tell(s) a computer what to do. - Code - All of the options listed - Commands - Instructions - Programs

All of the options listed

What is printed by the following code? int j = 33; j %= 3; System.out.println(j); - 11 - 2 - 0 - 33 - 1

0

To tell if a number is even or odd you MOD by ______. - 1 - even - 2 - 0

2

To declare a String variable x and set it equal to "Help" you would type: - x = "Help"; - String x = "Help"; - String x = "Help"; - string x = "Help";

String x = "Help";

What is output when the following code is executed? double num = (0 - 5) * 3; System.out.println(num);

-15.0

What is printed when the following code has been executed? int x = 15; int y = 4; System.out.println((2 * x + y) % x); - 2 - 19 - 4 - 34 - 15

4

What is the most precise primitive data type for storing decimal values? - double - String - int - None of the items listed - boolean

double

Is an int bigger or smaller in memory than a double? - smaller - bigger

smaller (An int is smaller than a double. An int is 32 bits and a double is 64.)

To find the ones digit of a number you MOD by _______. So for example the ones column of 3467 is 7. - 100 - 5 - 1000 - 10

10

What is the output when the following code is executed? int a = 89; double x = 78.2347; System.out.println(a / 2);

44

Which of the following would Java recognize as String? - "word" - "%.*_" - "1 8a" - "4b0ut T!me"

All of them

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. - Unlike primitive data types, reference data types cannot be stored by a variable. - Primitive data types contain multiple pieces of data, while reference types only store one value at a time. - Primitive data types cannot be read by a Scanner object and stored using a variable.

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

Suppose the variable n is used to store the String "Maeve" as shown: String n = "Maeve"; Which of the following will print "Hello my name is Maeve"? - System.out.println("Hello my name is n"); - System.out.println("Hello my name is " + n); - System.out.println("Hello my name is ")(n); - System.out.println("Hello my name is " - n); - System.out.println("Hello my name is ", n);

System.out.println("Hello my name is " + n);

The following code is to be used to get the name of a street from the user. Scanner scan = new Scanner(System.in); String streetName; System.out.println("Enter Street name"); /* 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 streetName? - streetName = nextLine(); - streetName = scan.nextLine(); - scan.nextLine() = streetName; - scan.nextLine(streetName); - scan.nextLine();

streetName = scan.nextLine();

Which line of code declares a double variable x and sets it equal to 5.0? - Double x = 5; - x = 5.0; - int x = 5.0; - double x = 5.0;

double x = 5.0;

Which of the following variable declarations is a correct assignment? - double y = 82; - String i = 82; - String w = 82.4; - double n = "s"; - int x = 97.2;

double y = 82;

Different data types can store different amounts of data. In the options below, which has the data types listed in order, from smallest to largest? - All the data types are the same size. - int, String, double, boolean - double, String, boolean, int - boolean, int, double, String - int, double, boolean, String

boolean, int, double, String

If you are owed $0.67 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 (67 in this case). - change + q - change - 25 - change / 25 - change - 17 - change % 25

change / 25

What data type should you use to hold the average of your test scores? - boolean - String - char - double - int

double

Executing which of the following lines of code would cause widening conversions to take place? - int a = 7.5 * 2; - double a = (double) 32 / 3; - double a = 17 / 5; - int a = (int) 18.3;

double a = (double) 32 / 3; double a = 17 / 5;

Assuming that scan is a properly initialized Scanner variable, which of the following correctly inputs a double? - double val = scan.nextDouble(); - double val = scan.nextLine(); - double val = scan.nextValue(); - double val = nextDouble(); - double val = scan.nextDouble;

double val = scan.nextDouble();

Which of the following are examples of primitive data types? - int - boolean - double - String - Scanner

int, boolean, double

To output: Hi There You would need to use: System.out.______("Hi "); System.out.print("There"); What would correctly replace ______ ? - output - println - input - String - print

print

Which of the following would Java interpret as being a String? - Hello World - 'Hello World' - "Hello World" - (Hello World) - {Hello World}

"Hello World"

Which of the following can a String NOT contain? - None of the items listed (meaning String can contain all of the listed types) - letters - digits - words - symbols

None of the items listed (meaning String can contain all of the listed types)

Which of the following is true about primitive data types? - They can only represent numeric data - They hold only one piece of data at a time - Primitives have built in methods - There are a total of 2 primitive types - They can hold words and numbers at the same time

They hold only one piece of data at a time.

What is x equal to after the following code has been executed: double x = 4.0; double y = 1.5x = x + 2 * y; - 7.5 - 7.0 - 11.0 - 9.0

7.0

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

78

What is wrong with the following code? String s = nextLine(); - Should be: String s = nextLine; - Should be: String s = next(); - Should be: String s = scan.nextLine(); - nextLine() method can't work with String variables - Nothing is wrong, that code won't generate any errors.

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

In Java all output uses the ______ data type. - scan - boolean - String - int - double

String

Put the following data types in order from largest to smallest (in terms of memory used). - String, int, boolean, double - String, double, int, boolean - String, double, boolean, int - String, boolean, int, double - String, boolean, double, int

String, double, int, boolean

What is 57 % 4? - 1 - 2 - 4 - 0 - 3

1

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

1

Which of the following expressions in Java is equal to 4? - 17 % 7 - 11 % 7 - 3 % 7 - 28 % 7 - 7 % 3

11 % 7

What does x equal after the following code has been executed? int x = 11; x++;

12

What is output when the following code is executed? double num = 2.0 * (46.75 - 40); System.out.println(num);

13.5

What is output when the following code is executed? int x = 18; x++; x++; x-=5; x*=2;x--; System.out.println(x);

29

What is 3 % 5? - 2 - 1 - 3 - 4 - 0

3

________ is when a computer checks your program for errors before running it. - Executing - All of the options listed - Compiling - Debugging - Programming

Compiling

What is printed by the following code? int y = (2 + 9) / 4; System.out.println(y); - 2.75 - Nothing is printed, the code causes an error. - 3 - 2 - 4.25

2

What is the largest value you can store in an int variable? - 256 - 65,535 - 1,024 - 2,147,483,647

2,147,483,647

What does x equal after the following code has been executed? int x = 13; x = x / 2; - 6.0 - 7 - 6 - 6.5

6

Which line of code properly casts a double to an integer? - double x = (int) 3.14; - int x = (int) 3.14; - int x = int(3.14); - int x = (double) 3.14;

int x = (int) 3.14;

To declare an integer variable x and set it equal to 17 you would type: - 17 = x; - int = 17; - int x = 17; - x = 17; - int 17 = x;

int x = 17;

Which line of code correctly declares and initializes the variable x to a value of 4? - integer x = 4 - int x: 4; - int x = 4; - x = 4;

int x = 4;

Assume the following has been typed in: Scanner scan = new Scanner(System.in); Which line of code declares an int x and sets it equal to input from the user? - int x = nextInt(); - int x = scan.nextInt() - int x = scan.int(); - int x = scan.nextInt();

int x = scan.nextInt();

Suppose we had declared a String variable called myString in a program. Which of the following lines would assign this variable to contain the String "Hi there"? - myString = "Hi there"; - "Hi there" = myString; - set myString to "Hi there" - String myString "Hi there" - myString: "Hi there";

myString = "Hi there";

Which of the following is a legal variable name in Java? - this.is.a.variable - int - name - 45house - the name

name

To output: Hi There You would need to use: System.out._____("Hi"); System.out.print("There"); - Print - println - print - Any of the options listed will work - Println

println

What is one reason we would use numeric casts in Java? - There is no reason to ever use casts unless you want to. - Java is unable to determine the data types correctly at run time without it - It is required by binary storage - There is a change that you lose data when you convert from a larger data types to a smaller data type. - There is a change that you lose data when you convert from a smaller data type to a larger data type.

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

What is wrong with the following code? String s; System.out.println(s); - The line, String s; , will cause an error - The line, System.out.println(s); should use a Scanner . - Variables cannot be printed. - You cannot print a String without setting its value. - System.out.println should be replaced with system.output.println

You cannot print a String without setting its value.

What is wrong with the code below? int x = 67.21; - The variable should be a String. - The value should not be rounded. - You cannot store a double in an int variable. - Nothing the code is fine as-is. - You cannot store an int in a double variable. - The variable should be a long.

You cannot store a double in an int variable.

What is output when the following code is executed? int x = -3; x++; x++; x--; System.out.println(x);

-2

Consider the following code: int y = 2147483647; y = y + 1; System.out.println(y); What number does the program print when compiled and run? Hint: think about the max value you just looked up in your previous answer. - 2147483648 - 0 - -1 - -2147483648 - This program crashes and raises an intOverflow exception.

-2147483648

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

2

A collection of characters enclosed in double quotes, such as "Hello world!" is given what name in Java? - String - Word - Thread - Print - Sentence

String

What will be printed to the screen when the following code runs? String s1 = "three"; String s2 = "five"; System.out.print(s1 + s2); - threefive - eight - fivethree - Nothing will be printed. We need to use double quotes in the print statement.

threefive

Which of the following is a legal variable name in Java? - 1test - a name - String - value - n.1

value


Ensembles d'études connexes

BIO139FALL2021/CHAP19HEART/SALADIN

View Set

AP Optional Final Semester 1 - Review

View Set

Ancient Egypt - Important Places

View Set

Слова іншомовного походження

View Set

JUST 212 Criminal Procedures Quiz's 8-14

View Set