Java Programming - Beginnings

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/21

flashcard set

Earn XP

Description and Tags

So fart: Printing, variables and types, user input, casting

Last updated 3:01 AM on 9/12/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

22 Terms

1
New cards

How do you print “Hello World.”?

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

2
New cards

How do you declare a variable that is all whole numbers and their negatives (integers)?

int num;

3
New cards

How do you declare a variable that is a real number that also has decimals?

double num;

4
New cards

How do you declare a variable that is a character of the alphabet?

char letter;

5
New cards

How do you declare a variable that represents a logical system that can only have one of two values: true/false, yes/no, etc?

boolean value;

6
New cards

How do you declare a variable that is composed of words

String words;

7
New cards

Why are strings unique?

Unlike int, double, boolean, or char, they are a non-primitive data type

8
New cards

User input for string?

String str = readLine(prompt);

9
New cards

User input for integer?

int num = readInt(prompt);

10
New cards

User input for double?

double myDouble = readDouble(prompt);

11
New cards

User input for boolean?

boolean bool = readBoolean(prompt);

12
New cards

Suppose you initialize two integer variables. How would you create variable sum, which represents the sum of both integers?

int sum = firstInteger + secondInteger;

13
New cards

Suppose a represents the int 20 and b represents the int 6. What would a / b result in?

Just 3; when dividing two integers, the result gets TRUNCATED.

14
New cards

If you divide two integers and the expected value is 3.9, what value does it truly become given the code is in Java?

Just 3; integer division always results in an integer and it is truncated, meaning rounding doesn’t occur

15
New cards

What is the result of 150 % 100

50

16
New cards

Is “#” an arithmetic operator

No; arithmetic means addition, subtraction, division, multiplication, and modulus

17
New cards

What is casting in Java?

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

18
New cards

What does (int) 9.9 simplify to?

9

19
New cards

How would you cast the double 10.9 to an int?

(int) 10.9 = 10;

20
New cards

How would you overcome integer division truncation?

Casting either the numerator or denominator as a double: 2 / (double) 3

21
New cards

While you could cast either the numerator or denominator for integer division, what is a more visually-appealing solution?

Casting outside of parentheses: (double) (2/3)

22
New cards

How do you round double values to the nearest integer value?

Add 0.5 to the double, then cast it to an integer will round it to the nearest integer.