Mock 2
Mock 2
CLASS-X
PRACTICE TEST-II (MCQ BASED)
Marks: 70 Time-90 min
SECTION A
(Attempt all questions)
Question 1.Tick the correct option (20x1=20)
1. . …………………….. Statement provides an easy way to dispatch execution to different parts of your code based on the
value of an expression.
A. if-else B. switch C. if D. while
2. if(a>b)
c=a;
else
c=b;
It can be written as :
A. c=(b>a)?a:b; B. c=(a!=b)?a:b; C. c=(a>b)?b:a; D. None of the above
3. if(a<0)
System.out.println(“a negative number”);
if(a>0)
System.out.println(“a positive number”);
if(a==0)
System.out.println(“the number is zero”);
The above comes under which of the following statements.
A. if statement B. if-else statement C. if else if statement D. nested if statement
4. public class temp
{
public static void main(String args[])
{
int x=1;
if((boolean)x==true)
System.out.println("True.");
else
System.out.println("False.");
}
}
A. True. B. False. C. Error
5. What will be the return value of the following function test?
int test()
{
int a=6, b=7;
int sum=a+b;
int pr=a*b;
return(sum);
return(pr);
}
A. 13 B. 42 C. 13,42 D. 42,13
9. The conditional statement, ………………. can only test for equality, whereas ………………. can evaluate any type of
Boolean expression.
A) if, switch B) switch, if C) while, if D) if, while
19. When the operators are having the same priority, they are evaluated from …………….. …………. in the order they appear in the
expression.
A) right to left B) left to right C) any of the order D) depends on the compiler
a) Find the output of the following program segment c) Find the output :
public static void main(String args[]) String str="The green bottle is in the green bag";
{int s=0; String str1="green";
int a[]={2,4,6,8}; System.out.println(str.indexOf(str1));
for(int i=0;i<=1;i++)
{ d) Find the output
s=a[i]+a[3-i]; char ch = 'k';
System.out.println(s); char chr = Character.toUpperCase(ch);
} int p = (int) chr;
System.out.println(chr + "\t" + p);
b) Find the output of the following program segment
public static void main(String s[]) e)String x="BLUE";
{ char c; String p=" "; int i;
int a,b=0; for(i=0;i<x.length();i++)
int c[]={12,13,14,15,16,17}; {
for(a=0;a<6;a++) c=x.charAt(i);
{ p=c+p;
if(a%2==0) System.out.println(p);
b+=c[a]; }
}
System.out.print(b) }
SECTION B
(Attempt any Four questions.) (10X4=40)
Question 3
Given below is a class with the following specifications
Class Name: Equivalent
Data members: int n – to store first number
int m – to store the second number
Member methods:
a)A parameterised constructor to initialise values to member variables.
b)int sumFactor(int num)- to return factors sum excluding number as its factor.
c)check()- A function to check whether number is an equivalent number or not.
Equivalent numbers are numbers where the factors sum(other than the number itself) are identical.
Ex 159 and 559 are equivalent numbers since their factors sum is same.
159=1,3 and 53= 1+3+53=57
559=1,13 and 43=1+13+43=57
Question 4
Write a program by using a class with the following specifications:
Class name — Salary
Data members — int basic
Member functions:
void input() — to input basic pay
void display() — to find and print the following:
da = 30% of basic
hra = 10% of basic
gross = basic + da + hra
Use a main function to create an object and call member methods of the class.
Question 5:
Using the switch statement, write a menu driven program for the following:
(i) To print the Floyd’s triangle [Given below] (ii) To display the following pattern:
1 I
23 IC
456 ICS
7 8 9 10 ICSE
11 12 13 14 15
For an incorrect option, an appropriate error message should be displayed.
Question 6
Write a program in Java to enter a String/Sentence and display the longest word and the length of the longest word present
in the String.
Sample Input: “TATA FOOTBALL ACADEMY WILL PLAY AGAINST MOHAN BAGAN”
Sample Output: The longest word: FOOTBALL: The length of the word: 8
Question 7
Write a program to input a binary number(base 2) and convert to its decimal equivalent(base 10)
SAMPLE INPUT : (110011)2
SAMPLE OUTPUT: (51)10
Question 8
Design a class to overload a function sum() as follows:
(i) int sum(int a, int b) to calculate and return the sum of all the even
numbers in the range a to b.
Sample Input:
a = 10
b = 20
Sample Output:
Sum = 90
(ii) double sum(double n) to calculate and return the product of the following series:
Product = 1.0 × 1.2 × 1.4 × … × N
(iii) int sum(int n) to calculate and return the sum of only odd
digits of the number N.
Sample Input: N = 43961
Sample Output: Sum = 13
Write the main() method to create an object and invoke the above methods.