1. List Java\'s 8 primitive data types: Part 2: Declaring variables (4 pts. each
ID: 3665604 • Letter: 1
Question
1. List Java's 8 primitive data types: Part 2: Declaring variables (4 pts. each) 2. Write the code to declare a float variable named weight and give it the value 115.5; 3. Write the code to assign the value 10 to the variable s, which has already been declared (see below). int s 4. Write the code to declare a char variable named letterB and assign it the value B. 5. Write the code to declare a boolean variable named isRaining and assign it the value true. Part 3: Calculations (4 pts. each will be the value of a after this statement int a 13 5 will be the value of b after this statement int b 13 s 5; will be the value of c after this statement: double c 13 5 will be the value of d after this statement int d. 12 6 2;Explanation / Answer
1)
byte
short
int
long
float
double
boolean
char
2)
class TestClass {
public static void main(String args[] ){
float weight = 115.5;
}
}
3)
class TestClass {
public static void main(String args[] ){
int s;
s=10;
}
}
4)
class TestClass {
public static void main(String args[] ){
char letterB = 'B';
}
}
5)
class TestClass {
public static void main(String args[] ){
boolean isRaining = true;
}
}
6)
Answer = 2
13/5 = 2.6,
since both numerator and denominator both are integer values , division will produce the intiger part of division, which is equal to 2
hence 2 will be assigned to a
7)
3
13%5 = 13 mod 5 = 3
hence 3 will be assigned to b
8)
Answer = 2.0
since both numerator and denominator both are integer values , division will produce the intiger part of division, which is equal to 2
hence 2 will be assigned to c , which will become 2.0 since it is a double
9)
Answer = 4
since the calculations are performed from left to right d = 12 / 6 *2 is equivalent to d = ( 12 / 6 ) * 2
12 / 6 will be calculated first, which will give 2, then this will be multiplied by 2 to give 4
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.