All Flashcards
What does the following code output?
java
int x = 5;
double y = 2.0;
System.out.println(x / y);
2.5
What does the following code output?
java
int a = 10;
a %= 3;
System.out.println(a);
1
What does the following code output?
java
int num = 7;
num++;
System.out.println(num);
8
What does the following code output?
java
double price = 19.99;
int roundedPrice = (int) price;
System.out.println(roundedPrice);
19
What does the following code output?
java
int result = 5 + 3 * 2;
System.out.println(result);
11
Identify the error in the following code:
java
int number = 4.5;
System.out.println(number);
Cannot assign a double value to an int variable. Requires explicit casting.
What does the following code output?
java
System.out.println(5 / 2);
System.out.println(5.0 / 2);
2 2.5
What does the following code output?
java
int x = 8;
x /= 2;
System.out.println(x);
4
What does the following code output?
java
boolean flag = true;
System.out.println(!flag);
false
What does the following code output?
java
int count = 10;
count -= 5;
System.out.println(count);
5
What are the differences between 'int' and 'double' data types in Java?
int: Stores whole numbers | double: Stores decimal numbers.
What are the differences between integer division and double division?
Integer division: truncates the decimal part | Double division: gives a decimal result.
What are the differences between age++ and age += 1?
age++: post-increment operator, increments after the current operation | age += 1: adds 1 to age.
What is a compiler?
A program that translates high-level code into machine code.
What is a class in Java?
A blueprint for creating objects.
What is a string literal?
An instance of the String class, representing a sequence of characters.
What is a primitive data type?
A basic data type that stores data directly in memory.
What is a variable?
A container for storing data values.
What is casting?
Changing the data type of a value.
What is the assignment operator?
The '=' symbol, used to assign a value to a variable.
What is a boolean?
A primitive data type with a value of either 'true' or 'false'.
What is the main method?
The entry point of a Java program.
What is the modulo operator?
The '%' symbol, which returns the remainder of a division.