Values & Datatypes
What are Literals?
What is a Variable?
Q1. Identify the literals listed below
0.4 ‘A’ “false” false 25
Q2. State the value of n and ch
char c = ‘C’;
int n = c+1;
char ch = (char)n;
Q3. State the value of n and ch
char c = ‘C’;
int n = c+32;
char ch = (char)n;
Q4. State the output
char c = ‘b’;
int n = c+1;
char ch = (char)n;
[Link](“The Character is ”+ch);
[Link](“TheValue is ”+n);
Q5. Write a Java statement to get following output.
“Hey, welcome to the world of coding!”, he said.
Q6. Arrange the following primitive data in ascending order of their size
long int double byte
Q7. Write the default value of float and String data type.
Q8. Name the type of conversion
int a=5; float f=5.6f; int ans=0;
ans= a+(int)f;
Q9. Choose the correct identifiers
1. Game 2. 5Rs. 3. Value 4. void
a. 1,3 and 4 b. 2 and 3
c. 3 and 4 d. 1 and 3
Q10. The statement [Link](“four”+2+2); give output as___.
a. four4 b. four22
c. four d. none
Q11. If a and b is of type float what would be the resultant data type of a *b?
a. int b. float
c. double d. char
Q12. The size of double data type in bits is_____
a. 80 bits b. 48 bits
c. 32 bits d. 64 bits
Q13. _______ precedes the variable during its declaration.
a. return type b. data type
c. class d. new
Q14. Name the type of conversion used in the below given
statements. Where a and b are int type.
long m=(long) (a/b *2.5);
a. Explicit b. Implicit
c. Both d. Invalid
Q15. Assertion(A): boolean data can only have a value of true or
false.
Reason(R): default value of Boolean data type is false.
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true and R is not the correct explanation of A.
c. A is true and R is false.
d. A is false and R is true.
Q16. Which of the following is smallest integer data type?
a. char b. int
c. byte d. double
Q17. Which of the following is an example of implicit type casting?
(a) int a = 2.3; (b) x = (double) a;
(c) a = 2 +3; (d) double d = 2.3;
Q18. Which of the following is allowed in an arithmetic statement in Java?
(a) [ ] (b) { }
(c) ( ) (d) All of these
Q19. Which of the following is an invalid variable name?
(a) BASICSALARY (b) _basic
(c) 2015_DDay (d) overtime
Q20. A character variable can at a time store ….
(a) 8 characters (b) 1 character
(c) 254 characters (d) Any number of characters
Programs
Q21. Simple to Compound Interest SI = (Principal * Rate * Time) / 100
Q22. Compound Interest to Simple Interest Amount = Principal * (1 +
Rate/100)^Time and CI = Amount - Principal
Q23. Feet to Inches :inches = feet * 12;
Q24. Inches to feet: feet = inches / 12
Q25. Meters to centimetres and vice versa
// Convert kilometers into meters
b=a*1000;
// Convert kilometers into centimeters
c=a*100000;
Q26. Celsius to Fahrenheit F = (C * 9/5) + 32 or F = (C * 1.8) + 32
Q27. Fahrenheit to Celsius : C= (Fahrenheit - 32) * 5 / 9
Solution
Q1
0.4 – Real Literals
‘A’ - Character Literals
“false” - String Literals
false – Boolean Literals
25 – Integer Literals
Q2
output
n = 68
ch=D
Q3
output
n=99
ch = c
Q4
output
The Character is c
TheValue is 99
Q5
[Link]("\"Hey, welcome to the world of coding!\", he said.");
Q6
byte int long double
Q7
Ans float a= 0.0f; String b= “”;
Q8
Explicit conversion