Answer the following questions1. If a value is in the range 1 to 10, what is the smallest type that can store it? 2. Which of the following declarations is illegal? a) long num; b) int value=10; c) char Ans='Y'; d) int = 29;3. A mathematical expression can be a sequence of any number of operands and operators (True / False) 4. The literal 216 is stored as an int (True / False)5. The literal 12.5 is stored as a double (True / False)6. Which is the correct order of operations for the Java expression? 12 * 2 - 4 / 2 + 9 a) * - / + b) * / - + c) * + - / d) + - / *7. Contents of variable a (below) will be stored in 2 bytes (True / False)char a = '9';8. Which of the following words are the keywords in Java language? a) transient b) package c) NULL d) export e) try f) catch g) instanceof h) break9. Which of the following are valid variable names in Java? a) Expiry_Card b) Salary$ c) _empno d) Customer no.10. + is addition operator and ................................................ operator. 11. The code given below will give no error (True / False) int num1 = 10; float n = (float)2.1; float res = num1 % n;12. Which of the following arithmetic expressions are valid? If valid, please give the value of the expression: a) 15.25 + -5.0 b) 21 % (int)4.5 c) (5 / 3) * 3 + 5 % 3 d) 14 % 3 + 7 % 213. Will there be information loss if a variable of type float is converted to double? (Yes / No) 14. Determine the value of each of the following logical expressions if a = 5, b = 10 and c = -6 a) a > b && a > c b) a < b && a > c c) a == c || b > a d) b > 5 && c < 0 || a > 0 e) (a / 2.0 == 0.0 && b / 2.0 != 0.0) || c < 0.015. Find errors if any, in the following assignment statements and rectify them. a) m = ++a * 5; b) a = b++ -c *2; c) s = / 5; d) p * = x / y;16. Identify unnecessary parentheses in the following arithmetic expressions: a) ((x -(y / 5) + z) % 8) + 25 b) ((x - y)* p)+ q c) (m*n) + (-x / y) d) x / (3 * y)17. Write an applet, in which you assign the values of x and y and print the results of the following expressions: a) (x + y)/(x - y) b) (x + y)/ 2 c) (x + y)(x - y)18. Write a program to read the following numbers, round them off to the nearest integers and print out the results in the integer form. a) 35.7 b) -23.73 c) 9201.283 d) -121.1119. Write a program in which you assign the name of the city, population of males and females in the city to the variables of appropriate data type. Then, display the ratio of females to males in the city. There should be no truncation in the result. 20. Write a program in which you assign any real number to the variable and display its floor and ceiling value as shown below: c:\>Enter a floating point value: 45.65 45 45.65 46 (where 45 is smaller integer than 45.65, 45.65 is the real number and 46 is the larger integer) |

Course Content > Session 2 >