0% found this document useful (0 votes)
3 views23 pages

Sample Java Papers Solved - Bluej For ICSE

The document contains solved sample Java question papers for ICSE, including various programming tasks and theoretical questions. It covers topics such as charge calculations, special two-digit numbers, month days, pattern displays, and series generation, along with explanations of Java concepts like data types, loops, and exceptions. The content is structured into sections with specific questions and answers, aimed at helping students prepare for their exams.

Uploaded by

Ashok Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views23 pages

Sample Java Papers Solved - Bluej For ICSE

The document contains solved sample Java question papers for ICSE, including various programming tasks and theoretical questions. It covers topics such as charge calculations, special two-digit numbers, month days, pattern displays, and series generation, along with explanations of Java concepts like data types, loops, and exceptions. The content is structured into sections with specific questions and answers, aimed at helping students prepare for their exams.

Uploaded by

Ashok Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

5/30/2018 Sample Java Papers Solved – Bluej for ICSE

Home Type and press enter

ICSE APC texbook Programs.

Mobile App

ICSE 2015 Computer Applications Paper Solved

ICSE eorey

Arrays

2014 ICSE Paper

Sample Java Papers Solved

About

Create an Android APP

Blue for ICSE

Sampl Jav Paper Solve

https://bluejforicse.wordpress.com/keys/ 1/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

A Simple Java Question Paper(Unit III)


By Teja

Section – A

Answer any four of the following :


1 . Write a Program to calculate charges for sending particles when the charges are as
follows
For the rst 1KG Rs.15.00 , For additional weight , for every 500gm or fraction thereof:
Rs 8.00
Ans
class Prog1
{
static void test(double wt)//user enters the weight in KGs
{
System.out.println(“Parcel Weight is “+wt);
int icharge = 15;
System.out.println(“Initial charge is “+icharge);
int rwt = (int)((wt-1)*1000);
System.out.println(“Remaining weight a ter deducing 1Kg “+rwt);
int rcharge = (rwt/500)*8;
System.out.println(“Charge excluding fractional part is Rs.”+(icharge+rcharge));
int fcharge = (rwt%500>0)?8:0;
System.out.println(“Charge for fractional part is Rs. “+fcharge);
int tcharge = icharge+rcharge+fcharge;
System.out.println(“Total Charge is Rs. “+tcharge);
}
}

2 . A special two-digit number is such that when the sum of its digits is added to the
product of its digits , the result is equal to original number
Example : 59
5+9 = 14
5*9 = 45
45+14 = 59 erefore , 59 is a special two digit number
https://bluejforicse.wordpress.com/keys/ 2/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

Write a program in java to check whether a number is special two-digit number or not
Ans
class Prog2
{
static void test(int num)//user inputs a two-digit number
{
int m = num;
int product = 1;
int sum = 0;
while(m>0)
{
int dig = m%10;
sum = sum+dig;
product = product*dig;
m/=10;
}
int nalsum = sum+product;
if( nalsum==num)
System.out.println(num+” is a special two digit number “);
else
System.out.println(num+ ” is not a special two digit number “);
}
}

3.Write a Java Program to accept a month using Scanner class , and display the
number of days present in that month
Ans :
import java.util.*;
class Prog3
{
static void test()
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter the number of month “);

https://bluejforicse.wordpress.com/keys/ 3/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

int choice = in.nextInt();


switch(choice)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println(“No. of days are 31 days “);
break;
case 4:
case 6:

case 9:
case 11:
System.out.println(“No .days are 30 days “);
break;
case 2:
System.out.println(“No. Of days are 28 or 29 “);

break;
default : System.out.println(“Wrong Choice “);
}
}
}

4.Write a program to display the following pattern :


13579
35791
57813
79135
91357
Ans
https://bluejforicse.wordpress.com/keys/ 4/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

class Program4
{
static void teja()
{

for(int i = 1,l=1;i<=5;i++,l+=2)
{
int k = 1;

for(int j = 1,m=l;j<=5;j++,m+=2)
{
if(m>9)
{
System.out.print(k+” “);
k+=2;
}
else
if(l==5&&m==9)
{
System.out.print(“8 “);
}
else
System.out.print(m+” “);
}
System.out.println();
}
}
}

5.Write a Program in java to obtain the rst eight numbers of the following series :
1,11,111,1111………………
class Prog5
{
static void test()
{
https://bluejforicse.wordpress.com/keys/ 5/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

double s=0.0;
int p;
for(int i = 0;i<=7;i++)
{
s=s+Math.pow(10,i);
p = (int)s;
System.out.print(p+” , “);
}
}
}

Section – B
Answer any Four
1.Java language provides various ways to get the data value within a program.
Compare the way of using Command line argument with the way of using Input
Stream
Ans
1.To take the input through the Input Stream method , ‘java.io’ package should be
imported as the Input Stream is de ned in that package whereas no package is
needed to be imported to take the input using Command Line Method
2.To take the input through the Input Stream Method , two classes , namely (i)
InputStreamReader , and (ii) Bu feredReader
whereas in Command Line method no class is needed to be declared.

2.Explain the following Math functions with their output by taking -8.76 as input
(i)Math. loor()
Ans : Math. loor(-8.76) returns in a double type value -9.0 , as
-9.0 is the next lowest number to -8.76
(ii)Math.ceil()
Ans:Math.ceil(-8.76) returns in a double type value -7.0 , as
-7.0 is the next highest number to -8.76

https://bluejforicse.wordpress.com/keys/ 6/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

3.What is the Syntax for :


(i)for loop
Ans :
for(initial value ; test condition ; step value)
{
Body of the loop
}
(ii)do….while loop
Ans :
Initial value
do
{
body of the loop
step value;
}
while(test condition);

4.What are the di ferences between if …else and switch…case ?


Ans :
1.If…else results in a Boolean type value whereas switch…case returns in a value of int
or char datatypes
2.If..else can also perform tests on Logical operations whereas switch…case can only
perform test for equality
3.If…else Can perform the test for Strings also whereas switch…case cannot perform
tests on String values
4.Default statement is applied in switch..case whereas it is not applied in if…else

5.What are the di ferences between Entry controlled loop and exit controlled loop ?
Ans :
1.Entry controlled loop is while loop whereas exit controlled loop is do…while loop
2.Do…while loop will execute at least once , even if the condition is not satis ed
whereas while loop will never execute if the condition is not satis ed
3.While loop will check the condition rst and then will execute the block whereas do…
while loop will execute the block rst and the check the condition

https://bluejforicse.wordpress.com/keys/ 7/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

Section – C
Fill in the blanks
1 . _________ is the process in which a program is validated and _________ is the
process in which the errors in the program are removed
Ans : (i)Testing , (ii) Debugging

2. e ___________ is a selective structure where several possible constant values are


checked for speci c vale
Ans : Switch case

3.A Java Program executes but doesn’t give the desired output and will not terminate
from the terminal window . en this is a ______________ error in the program
Ans:Logical Error

4 . A __________ statement in a Java Programming is enclosed in braces


Ans : Compund Statement

5.Generally , for the xed iterations ________ loop can be used and for the variable
iterations _________ loop can be used.
Ans : (i) for loop , (ii) while loop (or) do-while loop

Java Sample Question Paper 2 Solved(ICSE Model)

e paper is divided into two sections.Attempt all questions from Section-A and any four from
Section-B. e intended marks for questions or parts of questions are given in brackets[] , Follow
Case-sensitivity.

Section – A(40 marks)

Attempt all questions from this Section.

Question – 1

(a)What is the role of keyword ‘void’ in Java in declaring a function ? [2]

https://bluejforicse.wordpress.com/keys/ 8/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

Ans : e keyword ‘void’ in java is used to declare functions which do not return any
value of any datatype, ‘void’ does not return any data type.

Example : static void test()

here the method ‘test’ is declared as void and hence it returns no value.

(b) What does token ‘keyword’ refer to, in Java? [2]

Ans : It refers to the special words which are used in Java to perform some speci c
task.Every keyword has its own task to be performed, there were many keywords in
Java, which have di ferent built-in functions to be performed, when these keywords
are declared in Java programming, their built-in feature will be performed by them,
so these keywords perform an important role in Java programming

Example : the keyword ‘new’ is used in Java to declare an object of a class or any array
, with the help of this keyword , the object of that particular class gets stored in the
dynamic memory.

(c) How many kinds of variables are there in Java ? Name them [2]

Ans : ere are two types of variables in Java, namely :

1.static variables – ese variables are common to all the objects of a class, all the
objects of a class use these variables commonly.

2.non static variables – ese variables are not common to all the objects of a same
class , each object uses these variables seperately.

(d) What is the output of the following code : [2]

char c = ‘A’;short m=26;int n=c+m; System.out.println(n);

Ans : e output of the code will be : 91

e Ascii value of A is 65 , and hence the value of n , will be 65+26 = 91

(e)Write the general syntax of a Single Dimensional Array, and an example of each
primitive datatype? [2]

Ans : Syntax for declaring a Single Dimensional Array :


https://bluejforicse.wordpress.com/keys/ 9/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

<data type> <array name> = new <data type>[<size of the array>];

Example of each Primitive datatype: int i = 8;

loat f = 0.5;

double d = 1.2356;

String st = “Teja”;

char ch = ‘T’;

Question – 2

(a)State the di ference between primitive datatypes and user-de ned datatype [2]

Ans : e di ferences are :

1.Primitive datatypes are de ned implicitly , they are in-built datatypes whereas user-
de ned datatypes are de ned by the user during the execution of the program

2.Primitive datatypes are not dependent on any other datatypes whereas user-de ned
datatypes are directly or indirectly dependent on Primitive datatypes

Example of primitive datatypes : int, loat,double.String,char , etc

Example of user-de ned dataypes : class

(b)What are the types of type casting shown by the following and state the outcome
result? [2]

(i) loat a = ‘1’+’2′;

(ii) loat b = ( loat)(21/2);

Ans : (i) this is implicit type casting , the outcome will be 99 in loat datatype

(ii)this is explicit type casting, the outcome will be 10.5 in loat datatype

(c)What are the pre-conditions for binary search to be performed for a Binary search
be performed on a Single Dimensional Array? [2]

https://bluejforicse.wordpress.com/keys/ 10/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

Ans : e elements of the array should be in a sorted order i.e., either in ascending
order or in descending order

(d)Explain the terms : (i)Keyword ‘this’ (ii)Exception [2]

Ans : (i)Keyword ‘this’ : It is used in Java programming to reference the data members
of the current object of a class, there may be many objects in a class, and these objects
have di ferent values for their data members, therefore to point out to a particular
object , the keyword ‘this’ is used in Java Programming.

(ii)Exception : e unexpected error which is raised in the program during its


execution , is known as Exception, it can be managed by ‘Exception Handling’
Examples : Number Format Exception, String Out Of Bounds Exception , etc

(e)Mention any two characteristics of a Constructor ? [2]

Ans : e two characteristics of a Constructor are :

1.It has the same name as that of a class

2.It does not return any value of any datatype

Question – 3

(a)If the parameter ‘i’ is given the value of 10, in the following program then what is
the output [4]

class Recursive {

static void printArray(int i){

if(i!=0) printArray(i-1);

System.out.println(“Values are “+i);

}}

Ans : e output of the program will be :

Values are 0

https://bluejforicse.wordpress.com/keys/ 11/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

(b)Given the following expressions: A) val=10 B) val==10 [2]

(i)How do they di fer

(ii)What will be the result of the two if value of ‘val’ is 7 initially

Ans : (i) e expression in A is an assignment statement ,the value of ‘val’ is assigned


as 10 whereas the expression B is a test for equality, the value of ‘val’ is compared to 10.

(ii)When the value of ‘val’ is 7 initially, in A value ‘val’ changes from 7 to 10 and in B , it
will result in false as 10 is not equal to 7

(c)How are primitive datatypes and reference datatypes are passed in Java, while
invoking a function ? [2]

Ans : e primitive and reference types in Java are passed by actual and formal
parameters , the primitive datatypes are passed by ‘Pass by value’ and and reference
types are passed by ‘Pass by Reference’ , in ‘Pass by Value’ the values of the actual
parameters does not change even if there is a change in the formal parameters ,
whereas in ‘pass By Reference’ , the values of the actual parameters change with the
change in formal parameters.

(d)Write the output of the following program segment : [2]

public static void output() {

String n = “Computer Knowledge”;

String m = “Computer Applications”;

System.out.print(n.substring(0,8).concat(m.substring(9)));

System.out.print(n.endsWith(‘e’)); }

Ans : e output will be :

ComputerApplicationstrue

(e)What are the di ferent types of errors that can take place during the execution of a
program ? [2]

https://bluejforicse.wordpress.com/keys/ 12/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

Ans : e di ferent types of errors that can take place during the execution of a
program are :

1.Syntax Error

2.Run-time Error

3.Logical
Privacy & Cookies: Error
is site uses cookies. By continuing to use this website, you agree to their use.
To nd out more, including how to control cookies, see here: Cookie Policy

(f)What is delimiter ? Give few Examples [2] Close and accept

Ans : A delimiter is a special character used to input the values through scanner class
method, it seperates each token of an entered sentence, any text which is a ter a
delimiter will be considered as a seperate token. e default delimiter in Jva is White
space.

Examples of delimiters : Semi colon(;) , Coma(,) , Question mark(?) , Single


Quotation(‘) , Dot(.) , Not operator(!)

(g)Which OOP principle implements Function Overloading ? Explain [2]

Ans : Polymorphism implements Function Overloading , Polymorphism is the process


of declaring functions with the same name but for di ferent purposes and so is meant
by Function Overloading , therefore , Polymorphism implements Function
Overloading

(h) Java accomplishes encapsulation using visibility modes? Name them that are
available in Java [2]

Ans : e di ferent visibility modes available in Java are :

1. Public

2.Private

3.Protected

(i)Explain the term ‘type casting’ ? [2]

Ans : In a mixed arithmetic expression, which contains di ferent types of variables.


the result should be converted to a single data type. the process of converting the
https://bluejforicse.wordpress.com/keys/ 13/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

datatype of the result in a mixed arithmetic expression is known as type casting . It is


of two types :

1.Implicit type casting. it occurs according to the heirarchy of datatypes

2.Explicit type casting, it occurs on the intervention of the user

Section – B(60 marks)

Attempt any four questions from this section, each question carries 15 marks

Question – 4

Using Scanner class, write a program to accept a sentence and display only
‘Palindrome’ words. A word is said to be palindrome, if it appears to be same a ter
reversing its characters

Sample Input : MOM AND DAD ARE NOT AT HOME

Sample Output : MOM


DAD

Answer :

import java.util.*;
class Ques4
{
static void teja()
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter the Sentence : “);
while(in.hasNext())
{
String st = in.next();
int l = st.length();
String rev=””;
for(int i=0;i<l;i++)
{
char ch = st.charAt(i);

https://bluejforicse.wordpress.com/keys/ 14/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

rev=ch+rev;
}
if(st.equals(rev))
System.out.println(st);
rev=””;
}
}
}

Question-5

Write a program in Java to initialize and array of 10 distinct names and initialize
another array with their respective telephone numbers. Search for a name by the user
, in the list.If found , display “Search Successful” along with their phone number else
print “Search Unsuccessful, Name not enlisted”

Answer :

import java.util.*;
class Ques5
{
static void teja()
{
Scanner in=new Scanner(System.in);
String name[] =
{“Teja”,”Buncy”,”Sidhu”,”Sure”,”Banti”,”Imran”,”Arun”,”Suresh”,”Chaitu”,”Chanti”};
long tel[] =
{9848251,9848874,8143781,8654247,9654782,9654781,8742569,8485214,9854785,8475215};
System.out.println(“Enter the name to be searched : “);
String st= in.nextLine();
boolean isFnd= false;
for(int i=0;i<name.length;i++)
{
if(name[i].equals(st))
{
System.out.println(“Search Successful “);
System.out.println(“Telephone number is “+tel[i]);

https://bluejforicse.wordpress.com/keys/ 15/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

isFnd = true;
break;
}
}
if(!(isFnd))
System.out.println(“Search Unsuccessful , Name not enlisted”);
}
}
Question – 6

Write a program in Java to accept 10 integers in an array . Now display only those
numbers having complete square root

Sample Input : 12 , 45 , 49 , 78 , 64 , 77 , 81 , 99 , 45 , 33

Sample Ouput : 49 , 64 , 81

Answer :

class Ques6
{
static void teja(int [] m)
{
int l =m.length;
for(int i=0;i<l;i++)
{
for(int j=0;j<m[i];j++)
{
if(j*j==m[i])
System.out.println(m[i]);
}
}
}
}
Question – 7

De ne a class Employee having the following description :

https://bluejforicse.wordpress.com/keys/ 16/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

Data members/Instance variables :

pan : to store the personal account number

name : to store the name

tax : to store the annual taxable income

incometax : to store the tax that is calculated

Member Funtions :

Employee : default constructor

void input() : to accept pan number , name and tax

void calc() : to calculate the tax for an employee according to the given conditions :

Total Annual Taxable income

upto 100000 : No tax

From Rs. 100001 to Rs.150000 : 10% of income tax

From Rs.150001 to Rs.250000 : Rs.5000+20% of tax

Above 250000 : Rs.25000+30% of tax

void display() : to output the name, pan number , Taxable Income and income tax

Answer :

import java.util.*;
class Employee
{
Scanner in = new Scanner(System.in);
int pan;
String name;
int tax;
double incometax;
Employee()

https://bluejforicse.wordpress.com/keys/ 17/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

{
pan=0;
name=””;
tax=0;
incometax=0;
}
void input()
{
System.out.println(“Enter name : “);
String st = in.nextLine();
System.out.println(“Enter Pan : “);
int a = in.nextInt();
System.out.println(“Enter tax : “);
int b = in.nextInt();
name=st;
pan=a;
tax=b;
calc();
}
void calc()
{ int taxPer=0;
if(tax<=100000)
{
taxPer=0;
incometax=0;
}
else
if(tax>=100001&&tax<=150000)
{
taxPer = 10;
incometax=(10.0/100.0*tax);
}
else
if(tax>=150001&&tax<=250000)
{
taxPer = 20;
https://bluejforicse.wordpress.com/keys/ 18/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

incometax= 5000+(20.0/100.0*tax);
}
else
if(tax>250000)
{
taxPer = 30;
incometax = 25000+(30/100*tax);
}
display();
}
void display()
{
System.out.println(“PAN Number : “+pan);
System.out.println(“Name : “+name);
System.out.println(“Taxable Income : “+tax);
System.out.println(“Tax : “+incometax);
}
}

Question – 8

Write a Program to print the Pascalene triangle as follows :

Answer :

class Pascals_Triangle
{
static void test(int num)
{
int m[] = new int[20];
m[0]=1;
https://bluejforicse.wordpress.com/keys/ 19/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

int i,j;
for(i = 0;i<num;i++)
{
int a = m[i];
for(j=0;j<=i;j++)
System.out.print(m[j]+ ” “);
System.out.println();
for(j = i+1;j>0;j–)
m[j]=m[j]+m[j-1];
}
}
}

Question- 9

In an online competitive exam , a set of ‘N’ number of questions result in true or false,
If other than true or false are entered , answer will not be accepted and the question
will be repeated until either true or false is entered for that question

Using scanner class accept the no. of questions to be asked . Accept the answer for
each question, and print the frequency of true and that of false using Printwriter class

Answer :

import java.util.*;
import java.io.*;
class Ques9
{
static int k;
static String input()
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter the answer for “+k+” question “);
String st = in.nextLine();
return st;
}
static void main()

https://bluejforicse.wordpress.com/keys/ 20/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

{
PrintWriter pw = new PrintWriter(System.out,true);
k=1;
Scanner in = new Scanner(System.in);
pw.println(“Enter no. of questions to be asked “);
int n = in.nextInt();
int a=0;
int b=0;
for(int i=1;i<=n;i++)
{
String st = input();
if(!(st.equals(“true”)||st.equals(“false”)))
{
pw.println(“Enter either true or false only “);
st = input();
}
if(st.equals(“true”))
a++;
else
if(st.equals(“false”))
b++;
k++;
}
pw.println(“Frequency of true : “+a);
pw.println(“Frequency of false : “+b);
}
}

https://bluejforicse.wordpress.com/keys/ 21/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

Advertisements

Report this ad

Report this ad

Shar thi :

 Twitter  Facebook 1  Google

Like

One blogger likes this.

3 Comment

Pragathi REPLY
OCTOBER 29, 2014 — 4:15 PM

3rd blank ans is logical nah??

 Like

https://bluejforicse.wordpress.com/keys/ 22/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE

tejabluej (Post author) REPLY


OCTOBER 31, 2014 — 1:40 PM

ya..

 Liked by 1 person

1 Pingbac

Simple Java Question Paper with answers « bluejforicse

Leav Repl
Enter your comment here...

Blog at WordPress.com.

https://bluejforicse.wordpress.com/keys/ 23/23

You might also like