Little Star High School: Attempt All Questions
Little Star High School: Attempt All Questions
(a) What are the default values of the primitive data type int and float ? [2]
(b) Name any two OOP’s principles. [2]
(c) What are identifiers ? [2]
(d) Identify the literals listed below: [2]
(i) 0.5 (ii) ‘A’ (iii) false (iv) “a”
(e) Name the type of error (syntax, runtime or logical error) in each case given below: [2]
(i) Division by a variable that contains a value of zero.
(ii) Multiplication operator used when the operation should be division.
Question 2 [10]
Page 1 of 3
(e) Write one difference between / and % operator. [2]
(f) Write the output for the following : [2]
String s= “Today is Test”;
System.out.println(s.indexOf(‘T’));
System.out.println(s.substring(0, 7) + ” ” + “Holiday”);
(g) What are the values stored in variables r! and r2: [2]
(i) double r1=Math.abs(Math.min(-2.83,-5.83));
(ii) double r2=Math.sqrt(Math.floor(16.3));
(h) Give the output of the following code: [2]
String A = “26”, B=”100″;
String D =A+B+”200″;
int x = Integer.parselnt(A);
int y = Integer.parselnt(B);
int d = x+y;
System.out.println(“Result 1 = ”+D);
System.out.prinln(“Result 2 = “+d); ,
(i) Analyze the given program segment and answer the following questions : [2]
for(int i=3;i< =4;i+ +) {
for(int j=2;j<i;j+ +) {
System.out.print(” “); }
System.out.println(“WIN”); }
(i) How many times does the inner loop execute ?
(ii) Write the output of the program segment.
(f) What is the difference between the Scanner class functions next() and nextLine()? [2]
Question 5 [15]
Write a program in Java to find the largest among three numbers x, y, and z using ternary operator.
Accept the values of x, y and z from the user.
Question 6 [15]
Consider First n even numbers starting from zero(0) and calculate sum of all the numbers divisible by
3 from 0 to n. Accept the values of n from the user. Write a program in Java to print the sum.
Question 7 [15]
Write a program in Java to check whether the number is an Armstrong number or not. Armstrong
number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371
and 407 are the Armstrong numbers.
153 is an Armstrong number.
153 = (1*1*1)+(5*5*5)+(3*3*3)
where:
(1*1*1)=1
(5*5*5)=125
(3*3*3)=27
So:
1+125+27=153
Question 8 [15]
Using switch statement, write a menu driven program for the following :
(i) To find and display the sum of the series given below :
Page 2 of 3
S = x1 -x2 + x2 – x4 + x5 - …….– x20
(where x = 2)
(ii) To display the following series :
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.
Question 9 [15]
Write a program to accept a number and check and display whether it is a Niven number or not. [15]
(Niven number is that number which is divisible by its sum of digits).
Example:
Consider the number 126.
Sum of its digits is 1+2+6 = 9 and 126 is divisible by 9.
__________________________________________ X ______________________________________
Page 3 of 3