Sample Java Papers Solved - Bluej For ICSE
Sample Java Papers Solved - Bluej For ICSE
Mobile App
ICSE eorey
Arrays
About
https://bluejforicse.wordpress.com/keys/ 1/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE
Section – A
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
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 “);
}
}
}
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
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
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
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
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.
Question – 1
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.
here the method ‘test’ is declared as void and hence it returns no value.
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]
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.
(e)Write the general syntax of a Single Dimensional Array, and an example of each
primitive datatype? [2]
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]
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
(b)What are the types of type casting shown by the following and state the outcome
result? [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
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.
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 {
if(i!=0) printArray(i-1);
}}
Values are 0
https://bluejforicse.wordpress.com/keys/ 11/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE
(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.
System.out.print(n.substring(0,8).concat(m.substring(9)));
System.out.print(n.endsWith(‘e’)); }
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
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.
(h) Java accomplishes encapsulation using visibility modes? Name them that are
available in Java [2]
1. Public
2.Private
3.Protected
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
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
https://bluejforicse.wordpress.com/keys/ 16/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE
Member Funtions :
void calc() : to calculate the tax for an employee according to the given conditions :
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
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 :
Like
3 Comment
Pragathi REPLY
OCTOBER 29, 2014 — 4:15 PM
Like
https://bluejforicse.wordpress.com/keys/ 22/23
5/30/2018 Sample Java Papers Solved – Bluej for ICSE
ya..
Liked by 1 person
1 Pingbac
Leav Repl
Enter your comment here...
Blog at WordPress.com.
https://bluejforicse.wordpress.com/keys/ 23/23