1/35
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Write a program that computes the area of a circle
What is the purpose of declaring a variable?
To allocate memory for the variable’s data.
Import the Java scanner library implicitly.
import java.util.* ;
Import the Java scanner library explicitly.
import java.util.Scanner;
Create an instance of a scanner.
Scanner input = new Scanner(System.in);
Receive a double value from user input.
double d = input.nextDouble();
Identifier
the name of a variable
Identifiers can consist of what characters
Letters
Digits
Underscores
Dollar signs
An identifier cannot start with a…
Digit
An identifier cannot be the same as a…
reserved keyword
How long can an identifier be?
Any length
Declare an integer variable.
int x;
Declare a double variable.
double x;
Declare a character variable.
char x;
Assign the letter “B” to a declared character variable “ch“.
ch = ‘B’;
Declare and assign a variable in one line.
int x = 1;
Named constant
A variable whose value cannot be changed once it is assigned.
What is the keyword for declaring named constants?
final
Naming convention for named constants.
-All uppercase
-Underscores for spaces
ex: TAX_RATES
When should a value be assigned to a named constant?
Immediately after it is declared.
Naming convention for identifiers and methods.
-No spaces
-use all lowercase for the first word, and capitalize all subsequent words.
Write the remainder of 20 divided by 3 in Java.
20%3;
ans: 2
5/2 will result in…
2
5.0/2 will result in…
2.5
Today is Saturday, and your friends want to meet up in 10 days. Write a statement to determine what day of the week that will be.
Write a program that prompts a user to enter any number of seconds, reads it and then calculates the minutes and remaining seconds from it.
Storage size of byte data type.
8-bit signed.
Storage size of short data type.
16-bit signed.
Storage size of float data type.
32-bit |EEE 754
Storage size of double data type.
64-bit |EEE 754
Are values of the float data type stored accurately?
No, values are approximates.
Are values of the int data type stored accurately?
Yes
What is the result of:
System.out.println(1.0 - 0.9);
0.09999999999999998, not 0.1
Calculate 2 to the power of 3
Math.pow(2, 3)
Literal
A value that appears directly in the program.
ex: in int i = 34, the literal is 34
What is the result:
byte b = 1000
Compilation error. 1000 is too large to store with the byte data type.