In this ICSE sample paper there are two sections (Section A , 40 marks theory and Section B- 60 marks programs are asked). You are supposed to answer all the questions from section A, and any four from section B.
Watch java videos
ICSE sample paper
Section A (40 marks)
1.
- Give one example each of a primitive data type and a composite data type. [2]
- Complete the code below to create an object of Scanner class. [2]
Scanner sc= ________ Scanner( ________________)
- Create a class with one integer instance variable. Initialize the variable using : [2]
- i) Default constructor ii) Parameterized constructor
- Write an expression in java for a3-y5 [2]
- What is the use of default in a switch? [2]
2.
- Write a main difference between while loop & do while loop [2]
- Write the output of the following code. [1]
String str=”Application”;
System.out.println(str.charAt(4));
- Write the output of the following. [4]
String s1 = “MINORITY”;
String s2 = “REPORT”;
- out.println(s1.substring(0,3).concat(s2.substring(3,5))
- out.println(s2.substring(2));
- out.println(s1.charAt(s1.indexOf(‘R’) + s2.indexOf(‘R’)));
- out.println(s2.replace(‘p’ , ‘s’));
- Give an example of Relational operator and a Bitwise Operator. [1]
- Differentiate between equals() and compareTo() functions. [2]
- Name any two jump statements and their use. [2]
- What is a constructor? What is its use? [2]
- State the purpose and return data type of the following String functions :- [2]
- i) trim()
- ii) charAt( )
- What is the value stored in variable val given below: [2]
double val= Math.pow(“345”.indexOf(‘5’),3);
- What are the values of a and b after the following function is executed, if the values passed are 39 and 20: [2]
void paws(int a, int b)
{
a=a+b;
b=a-b;
a=a-b;
System.out.println(a+”,”+b);
}
4.
- Analyse the following program segment and determine how many times the loop will be executed and what will be the output of the program segment. [2]
int k=1,i=2;
while(++i<6)
k*=i; System.out.println(k);
- If int y=10 then find int z=(++y * (y++ + 5)); [2]
- Differentiate between isUpperCase(char) and toLowerCase(char) [2]
- State the output of the following program segment: String str1=”great”;
String str2=”minds”; System.out.println(str1.substring(0,2).concat(str2.substring(1)));
System.out.println(“WH”+(str1.substring(2).toUpperCase()))); [2]
- Write a statement to create an object of a class Student that invokes a parameterized constructor that accepts one String and one int type values. [2]
Section B (60 marks)
Attempt any 4 questions out of 6
5.Write a program in Java to accept a line of text from the user and create a new word formed out of the first letter of each word.
E.g. Mangoes Are Delivered After Midnight
Output: MADAM [15]
- Write a program to generate the following pattern [15]
- a)
B
B l
B l u
B l u e
B l u e j
b)
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
7. Write a program in java to accept a string and find [15]
- number of blank spaces in the string
- number of words in the string
- number of consonants present in the string
- number of vowels present in the string
- Write a class in java to enter any number and print if it is a perfect number.[Hint: a number is said to be perfect if it is equal to sum of all its factors ex, 6=1+2+3, hence 6 is perfect number] [15]
- a. Using switch case create class which take day number 1-7 & prints the corresponding day in words [3- Wednesday, 5- Friday] [7] b. Write a class to input a number and print if it is a prime number or not. [8]
- Define a class named movieMagic with the following description: Instance variables/data members:
<tbody>
int year
–
to store the year of release of a movie
String title
–
to store the title of the movie.
float rating
–
to store the popularity rating of the movie.
</tbody>
(minimum rating = 0.0 and maximum rating = 5.0)
Member Methods:
(i) movieMagic() Default constructor to initialize numeric data members to 0 and String data member to “”.
(ii) void accept() To input and store year, title and rating.
(iii) void display() To display the title of a movie and a message based on the rating as per the table below.
<tbody>
Rating
Message to be displayed
0.0 to 2.0
Flop
2.1 to 3.4
Semi-hit
3.5 to 4.5
Hit
4.6 to 5.0
Super Hit
</tbody>
Write a main method to create an object of the class and call the above member methods. [15]