Primitives

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

True or false: All variables must be declared before use.

True

What Java Data Type would be the best suited to represent whether or not a student has completed their homework?

boolean

What Java Data Type would be best suited to represent the amount of money in someone's bank account?

double

char initial = ____? "k" 'karel' "karel" 'k'

'k'

What are the five basic arithmetic operators?

+ - / * %

What is the value of modulo after running the code? int num = 2; int modulo = 15; modulo %= num;

1

What is the value of num after the code runs? int num = 225; num /= 15; System.out.println(num);

15

What is the value of age after the code runs? int age = 16; age++; age--; age++;

17

What is the output of the code snippet? int num = 2; int dividend = 5; dividend /= num; System.out.println(dividend);

2 It is not 2.0 because it is an int It is not 2.5 because Java truncates division between ints

What is the result? 150 % 100

50

What does this evaluate to? (int) 9.9

9

What will be the output of the following code snippet? int total = 100; int numPeople = 40; double average; average = total / (double) numPeople; System.out.println("Average: " + average);

Average: 2.5

What Java Data Type would be the best suited to represent the number of days left until the AP Computer Science Exam?

int

What is the correct line of code needed to request a whole number from a user? Assume a Scanner object called input has already been created.

int num = input.nextInt();

Name the primitive data types we have studied so far. (there are four)

int, char, boolean, double

What is the difference between int and double?

ints are only whole numbers while doubles are decimals

What is casting in Java?

Casting is turning a value of one type into another type.

True or false: String is a primitive

False

What does = mean in Java?

It is an assignment of the right hand side value to the left hand side variable.

What does the keyword final do?

It prevents variables from being altered.

What is printed after this code runs? public static void main(String args[]){ final int z; z = 20; z = 30; System.out.println(z); }

It throws an error because you can't change a value when final is used.

What are the requirements for naming variables in Java?

Must start with letter, $, or _ should use lower camel case

Primitive or Reference: A variable is the name given to a memory location.

Primitive

Primitive or Reference: The value stored in a variable can be changed during program execution.

Primitive

What is the correct syntax for creating a Scanner?

Scanner objectName = new Scanner(System.in);

What will this code segment print? System.out.println("Hello"); System.out.println("World");

Separate lines

What code will print "Hello Karel" to the screen?

System.out.println("Hello Karel");

What is the proper way to declare and initialize a variable in Java?

type name = value; For example, double cost = 3.25

What do x, y, and z equal after this code runs? int x = 7; double y = 2.0; boolean z = false; x = x + 3; z = true;

x = 10, y = 2.0, and z = true


संबंधित स्टडी सेट्स

International Business Operations Exam 1 (CH 1-3)

View Set

Anthropology Chapter 4: Globalization

View Set

Stats 110 Final - Fall Semester 2019

View Set

MODELOS DE INTERVENCIÓN, TEORÍA Y MÉTODO

View Set

Lecture 13 & 14 - Cumulative Trauma Disorders (CTDs)

View Set

Prebles Artforms Chapter 1: The Nature of Art and Creativity

View Set

Chapter 18: Health Problems of the Adolescent

View Set

Ch1. Managerial Accounting & Cost Concepts

View Set