QUESTION BANK
S td.: X Sub.: Computer Topic : Last 10 years
papers
Name: ____ Div.: _________ Roll No.:____________
SECTION A (40 Marks)
nswer all questions from this Section
A
Ch : 1 Revision of Class IX Syllabus
(a) Name any two basics Principle of Object-OrientedProgramming ( 2019)
( b) Write a difference between Unary and BinaryOperator (2019)
(c) Name the keywords which: (2019)
(i) indicates that a method has no return type
(ii) makes the variable as a class variable
(d) Write the memory capacity (storage size) ofs hort and float data type in bytes (2019)
(e) Identify and name the following tokens: (2019)
( i) public
(ii) ‘a’
(iii) ==
(iv) { }
( f) Differentiate between if else if and switch cases tatements (2019)
(g) What are the various types of errors in Java? (2019)
(h) Write a Java expression for the following: (2019)
|x²+2xy|
(i) Write the return data type of the followingfunctions: (2019)
(i) startsWith()
(ii) random()
(j) If the value of basic = 1500, what will be thevalue of tax after the following statement is executed
tax = basic > 1200 ? 200 : 100 (2019)
(k) Give the output of the following code and mentionhow many times loop will execute? (2019)
int i;
for(i=5;i>=1;i--)
{
if(i%2==1)
continue;
System.out.print(i+" ");
}
(l) Give the Output of the following: (2019)
Math.sqrt(Math.max(9,16))
(m) Evaluate the following expression if the valueof x=2, y=3 and z=1. (2019)
v = x + - --z + y++ + y
( n) Define abstraction. (2018)
(o) Classify the following as primitive or non-primitivedatatypes: (2018)
(i) char
(ii) arrays
SGVP International School, Ahmedabad - INDIA Page1of25
( iii) int
(iv) classes
( p) State the difference between while and do whileloop. ( 2018)
(q) Write the return data type of the followingfunction. (2018)
(i) endsWith() (ii) log()
(r) Write a Java expression for the following: (2018)
3𝑥 + 𝑥2 / a+b
(s) hat is the value of y after evaluating theexpression given below?
W
y+= ++y + y-- + --y; when int y=8 (2018)
(t) Give the output of the following:
(i) Math.floor (-4.7) (ii) Math.ceil(3.4) + Math.pow(2,3) ( 2018)
(u) Write the output for the following: (2018)
System.out.println("Incredible"+"\n"+"world");
(v) Convert the following if else if construct intos witch case (2018)
if( var==1)
System.out.println("good");
else if(var==2)
System.out.println("better");
else if(var==3)
System.out.println("best");
else
System.out.println("invalid");
(w) Rewrite the following using ternary operator: (2018)
if (bill > 10000 )
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;
(x) Give the output of the following program segmentand also mention how many times the
loop is executed: (2018)
int i;
for ( i = 5 ; i > 10; i ++ )
System.out.println( i );
System.out.println( i * 4 );
( y) What is Inheritance? ( 2017)
(z) Name the operators listed below (2017)
i) <
ii) ++
iii) &&
iv) ?:
( aa) State the number of bytes occupied by char andint data types. ( 2017)
(ab) Write one difference between / and % operator. (2017)
(ac) ive the output of the following program segmentand also mention the number of times the
G
loop is executed:
SGVP International School, Ahmedabad - INDIA Page2of25
(2017)
int a,b;
for(a=6,b=4;a<=24;a=a+6)
{
if(a%b==0)
break;
}
System.out.println(a);
(ad) Write a Java expression for the following : (2017)
ax5 + bx3 + c
(ae) What is the value of x1 if x=5 ? (2017)
x1 = ++x – x++ + –x
( af) Why is an object called an instance of a class? ( 2017)
(ag) Convert following do-while loop into for loop. (2017)
int i=1;
int d=5;
do {
d=d*2
System.out.println(d);
i++;
} while(i<=5);
(ah) hat are the values stored in variables r1 andr2:
W (2017)
i) double r1 = Math.abs(Math.min(-2.83,-5.83));
ii) double r2 = Math.sqrt(Math.floor(16.3));
(ai) Analyze the given program segment and answerthe following questions (2017)
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.
( aj) Define Encapsulation. ( 2016)
(ak) What are keywords? Give an example. (2016)
(al) Name the type of error (syntax, runtime or logicalerror) in each case given below: (2016)
(i) Math.sqrt (36-45) (ii) int a;b;c;
( am) S tate the difference between == operator andequals() method. ( 2016)
(an) What are the types of casting shown by the followingexamples: (2016)
(i) char c = (char)120;
(ii) int x = ‘t’;
SGVP International School, Ahmedabad - INDIA Page3of25
( ao) ame any two types of access specifiers.
N (2016)
(ap) Give the output of the following Math functions: (2016)
(i) Math.ceil(4.2)
(ii) Math.abs(-4)
(aq) Write down java expression for : (2016)
T = square root (A2 + B2 + C2)
(ar) Rewrite the following using ternary operator : (2016)
if(x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");
(as) Convert the following while loop to the corresponding for loop : (2016)
int m = 5, n = 10;
while (n>=1)
{
System.out.println(m*n);
n–-;
}
(at) Write one difference between primitive datatypes and composite data types. (2016)
(au) Analyze the given program segment and answerthe following questions: (2016)
(i) Write the output of the program segment
(ii) How many times does the body of the loop gets executed?
for(int m=5; m<=20; m+=5)
{
if(m%3 == 0)
break;
else
if(m%5 == 0)
System.out.println(m);
continue;
(av) Give the output of the following expression: (2016)
a+=a++ + ++a + -–a + a-– ; when a = 7
(aw) What are the default values of the primitivedatatypes int and float? (2015)
( ax) Name any two OOP’s principles. (2015)
(ay) What are identifiers? (2015)
(az) Identify the literals listed below: (2015)
(i) 0.5 (ii) ’A’ (iii) false (iv) “a”
(ba) Evaluate the value of n if the value of p=5,q=19 (2015)
int n = (q-p) > (p-q) ? (q-p) : (p-q);
(bb) Arrange the following primitive data types inan ascending order of their size: (2015)
(i) char (ii) byte (iii) double (iv) int
(bc) What is the value stored in variable res givenbelow: (2015)
double res = Math.pow(“345”.indexOf(‘5’), 3);
(bd) The access specifier that gives most accessibilityis __________ and the least accessibility is
___________ (2015)
SGVP International School, Ahmedabad - INDIA Page4of25
(be) ( i) Name the mathematical function which is used to find sine of an angle given in radians
(ii) Name a string function which removes the blanks paces provided in the prefix and suffix of a
s tring (2015)
2 2
(bf) Write the Java expression for: a +b /2ab (2015)
(bg) If int y = 10 then find int z = (++y * (y+++ 5)); (2015)
(bh) Which of the following are valid comments? (2014)
(i) /*comment */ (ii) /*comment (iii) //comment (iv)*/comment*/
(bi) Name the primitive data type in Java that is: (2014)
(i) a 64-bit integer and is used when you needa range of values wider than those provided by
int.
(ii) a single 16-bit Unicode character whose defaultvalue is ‘\u0000’.
(bj) State one difference between floating pointliterals float and double. (2014)
(bk) Operators with higher precedence are evaluatedbefore operators with relatively lower precedence.
Arrange the operators given below in order of higher precedence to lower precedence. (2014)
(i) && (ii) % (iii) >= (iv) ++
(bl) Identify the statements listed below as assignment,increment, method invocation or object
creation statements. (2014)
(i)System.out.println(“Java”);
(ii)costPrice = 457.50;
(iii)petrolPrice++;
(iv)Car hybrid = new Car();
(bm) Give two differences between switch statementand if-else statement. (2014)
(bn) What is an infinite loop? Write an infiniteloop statement. (2014)
(bo) List the variables from those given below thatare composite data types. (2014)
(i)s tatic int x;
(ii)arr(i) = 10;
(iii)obj.display();
(iv)boolean b;
(v)private char chr;
(vi)String str;
(bp) What are the final values stored in variablesx and y below? (2014)
double a = -6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a, b));
(bq) Rewrite the following program segment usingthe if-else statements instead of the ternary
operator. (2014)
String grade = (marks >= 90)? "A" : (marks >= 80)? "B" : "C";
(br) Give the output of the following method: (2014)
public static void main(String() args){
int a = 5;
a++;
System.out.println(a);
a -= (a--) - (--a);
System.out.println(a);
SGVP International School, Ahmedabad - INDIA Page5of25
}
(bs)Study the method and answer the given questions: (2014)
public void sampleMethod(){
for(int i = 0; i < 3; i++){
for(int j = 0; j < 2; j++){
int number = (int)(Math.random() * 10);
System.out.println(number);
} } }
(i)How many times does the loop execute?
(ii)What is the range of possible values stored inthe variable number?
(bt) What is meant by precedence of operators ? (2013)
(bu) What is a literal ? (2013)
(bv) State the Java concept that is implemented through: (2013)
(i)a superclass and a subclass.
(ii)the act of representing essential featureswithout including background details.
(bw) What are the types of casting shown by the followingexamples? (2013)
(i)double x = 15.2;
(ii)int x = 12;
int y = (int) x;
long y = x;
(bx) What is the difference between a break statementand a continue statement when they occur in a
loop? (2013)
(by) Name the Java keyword that : (2013)
(i) indicates that a method has no return type.
(ii) s tores the address of the currently-callingobject.
(bz) What is an exception ? (2013)
(ca) Write a Java statement to create an object mp4 of class digital. (2013)
(cb) What does a class encapsulate ? (2013)
(cc) Rewrite the following program segment usingthe if ..else statement (2013)
comm = (sale >> 15000) ? Sale × 5/100 : 0;
(cd) How many times will the following loop execute? What value will be returned ? (2013)
int x = 2, y = 50;
do {
++ x;
y – = x ++;
} while (x < = 10);
return y;
(ce) Write a Java expression for ut + 12 at2. (2013)
(cf) What is the final value of ctr when the iterationprocess given below, executes ? (2013)
int ctr = 0;
for (int i = 1; i < = 5; i ++)
for (int j=1; j < = 5; j + = 2)
++ ctr;
(cg) Give one example each of a primitive data typeand a composite data type. (2012)
(ch) Give one point of difference between unary andbinary operators. (2012)
SGVP International School, Ahmedabad - INDIA Page6of25
(ci) Write a Java expression for 2as+u2−−−−−−−√ (2012)
(cj) ame the type of error (syntax, runtime or logicalerror) in each case given below :
N (2012)
(i) Division by a variable that contains a valueof zero.
(ii) Multiplication operator used when the operations hould be division.
(iii) Missing semicolon.
(ck) Complete the code below to create an objectof Scanner class : (2012)
Scanner sc = ………. Scanner (………).
(cl) What are the values of x and y when the followings tatement are executed ? (2012)
int a =63, b=36;
boolean x=(a>b)?true:false;
int y=(a<b)?a:b;
(cm) What will be the result stored in x after evaluatingthe following expression? (2012)
int x=4; x+=(x++)+(++x)+x;
( cn) Give the output of the following program segment: (2012)
double x=2.9, y=2.5;
System.out.println(Math.min(Math.floor(x),y));
System.out.println(Math.max(Math.ceil(x),y));
(co) Rewrite the following program segment usingwhile instead of for statement, (2012)
int f=1,i;
for(i=1; i<=5; i++)
(f*=i; System.out.println(f);}
(cp) What is the difference between an object anda class? (2011)
(cq) What does the token ‘keyword’ refer to, in thecontext of Java ? Give an example for keyword.(2011)
(cr) State the difference between entry controlledloop and exit controlled loop. (2011)
(cs) What is the difference between / and % operator? (2011)
(ct) What is the role of keyword void in declaringfunctions? (2011)
(cu) Analyse the following program segment and determinehow many times the loop will be
executed and what will be the output of the program segment? (2011)
int p= 200;
while(true)
{
if(p<100)
break;
p=p-20;
}
System.out.println(p);
(cv) What will be the output of the following code? (2011)
(i) int k=5, j=9;
k+= k++ – ++j +k;
System.out.println(“k=”+k);
System.out.println(“j=”+j);
(ii) double b =-15.6;
double a = Math.rint(Math.abs(b)); –
System, out. println(“a=”+a);
SGVP International School, Ahmedabad - INDIA Page7of25
( cw) W rite an expression in Java for z=5x3+2yx+y. (2011)
(cx) Name the keyword that (2011)
(i) informs that an error has occurred in an input/ output operation.
(ii) distinguishes between instance variables andclass variables.
Ch : 2 Library Class
(a) State the data type and value of res after thefollowing is executed (2019)
char ch=’9′;
res = Character.isDigit(ch);
(b) What is meant by a package.Give an example (2019)
(c) (i) int res = 'A'; (2018)
What is the value of res?
(ii) Name the package that contains wrapper classes.
(d) Name any two library packages. (2016)
(e) Write the return type of the following libraryfunctions : (2016)
(i) isLetterOrDigit(char)
(ii) replace(char,char)
(f) Name the wrapper class of char type and booleantype. (2015)
(g) State the data type and the value of y afterthe following is executed : (2015)
char x = ‘7’;
y = Character.isLetter(x);
(h) State the package that contains the class : (2015)
(i)BufferedReader
(ii)Scanner
(i) What is meant by a package? Name any two JavaApplication Programming Interface package.(2015)
(j) What is the data type returned by the libraryfunctions: (2014)
(i)compareTo()
(ii)equals()
(k) What will be the output when the following codes egments are executed? (2014)
String s = "1001";
int x = Integer.valueOf(s);
double y = Double.valueOf(s);
System.out.println("x = " + x);
System.out.println("y = " + y);
(l) Name any two wrapper classes. (2013)
(m) What is the data type that the following libraryfunctions return ? (2013)
(i) isWhitespace (char ch)
(ii) Math.random()
(n) State the values of n and ch. (2012)
char c=‘A’;
int n=c+1;
char ch=(char)n;
(o) What are library classes ? Give an example. (2011)
SGVP International School, Ahmedabad - INDIA Page8of25
h : 3Arrays
C
(a) What is the difference between linear search& binary search technique (2019)
(b) Differentiate between searching and sorting. (2018)
(c) Consider the following String array and givethe output (2018)
String arr()= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"};
System.out.println(arr(0).length() > arr(3).length());
System.out.print(arr(4).substring(0,3));
(d) String x() = {“SAMSUNG”, “NOKIA”, “SONY” , “MICROMAX”,“BLACKBERRY”};
Give the output of the following statements: (2017)
(i) System.out.println(x(1));
(ii) System.out.println(x(3).length());
(e) Name of the following: (2017)
(i) A keyword used to call a package in the program.
(ii) Any one reference data types.
(f) If int x() = { 4, 3, 7, 8, 9, 10 }; what arethe values of p and q? (2016)
(i) p = x.length (ii) q = x(2) + x(5) * x(1)
(g) (i) What will the code print? (2015)
int arr() = new int (5);
System.out.println(arr);
(i) 0 (ii) garbage value (iii) 0000 (iv) values tored in arr(0)
(ii) Name the keyword which is used to resolvethe conflict between method parameter and
instance variables/fields
(h) Find the errors in the given program segmentand re-write the statements correctly to assign
values to an integer array. (2014)
int a = new int(5);
for(int i = 0; i <= 5; i++) a(i) = i;
(i) Write statements to show how finding the lengthof a character array char ( ) differs from finding
the length of a String object str. (2013)
(j) If int n ( ) = {1, 2, 3, 5, 7, 9, 13, 16}, whatare the values of x and y? (2013)
x = Math.pow (n(4), n (2));
y = Math.sqrt (n(5)+n(7);
(k) What is an array ? Write a statement to declarean integer array of 10 elements. (2012)
(l) Name the search or sort algorithm that : (2012)
(i) Makes several passes through the array, selectingthe next smallest item in the array each
time and placing it where it belongs in the array.
(ii) At each stage, compares the sought key valuewith the key value of the middle element of
the array.
(m) State the total size in bytes, of the arraysa (4) of char data type and p(4) of float data type. (2011)
(n) Write one difference between Linear Search andBinary Search. (2011)
Ch : 4 String Handling
(a) Give the output of the following code (2019)
String P=”20″,Q=”19″;
int a=Integer.parseInt(P);
int b=Integer.valueOf(Q);
System.out.println(a+””+b);
SGVP International School, Ahmedabad - INDIA Page9of25
(b) rite the output of the following:
W (2019)
String s1=”phoenix”;String s2=”island”;
System.out.println(s1.substring(0).concat(s2.substring(2)));
System.out.println(s2.toUpperCase());
(c) String x()={“Artificial intelligence”,”IOT”,”Machinelearning”,”Big data”}: (2019)
Give the output of the following statements:
(i) System.out.println(x(3));
(ii) System.out.println(x.length);
( d) Write a difference between the functions isUpperCase() and toUpperCase( ). (2018)
(e) System.out.print("BEST ");
System.out.println("OF LUCK");
Choose the correct option for the output of the above statements (2018)
(a) BEST OF LUCK (b) BEST
OF LUCK
(g) Give the output of the following string functions: (2018)
"ACHIEVEMENT".replace('E', 'A')
"DEDICATE".compareTo("DEVOTE")
(h) State the data type and value of res after thefollowing is executed : (2017)
char ch = ‘t’;
res = Character.toUpperCase(ch);
(i) Write the Output: (2017)
char ch= 'F';
int m=ch;
m=m+5;
System.out.println(m+ " " +ch);
(j) Write the output for the following: (2017)
String s= "Today is Test";
System.out.println(s.indexOf('T'));
System.out.println(s.substring(0,7)+ " "+ "Holiday");
(k) Give the output of the following code: (2017)
String A= "26", B= "100";
String D=A+B+ "200";
int x= Integer.parseInt(A);
int y=Integer.parseInt(B);
int d=x+y;
System.out.println("Result 1=" +D);
System.out.println("Result 2="+d);
( l) What is the difference between the Scanner classfunctions next() and nextLine()? ( 2017)
(m) Give the output of the following string functions: (2016)
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPI”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)
(n) State the output of the following program segmentis executed: (2015)
String a = “Smartphone”, b = “Graphic Art”;
String h = a.substring(2, 5);
String k = b.substring(8).toUpperCase();
SGVP International School, Ahmedabad - INDIA Page10of25
S ystem.out.println(h);
System.out.println(k.equalsIgnoreCase(h));
(o) Write the output of the following code segment: (2015)
char ch;
int x = 97;
do {
ch = (char) x;
System.out.print(ch + " ");
if (x % 10 == 0)
break;
++x;
} while (x <= 100);
(p) State the output of the following program segment: (2014)
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())));
(q) State the value of characteristic and mantissawhen the following code is executed: (2014)
String s = "4.3756";
int n = s.indexOf('.');
int characteristic = Integer.parseInt(s.substring(0, n));
int mantissa = Integer.valueOf(s.substring(n + 1));
(r) State the values stored in the variables str1 and str 2 (2013)
String s1 = “good”; Strings s2 = “world / matters”;
String str 1 = s2. substring (5). replace (‘t’, ‘n’);
String str 2 = s1. concat (str 1);
(s) Name the methods of Scanner class that: (2013)
(i) is used to input an integer data from the standardinput stream
(ii) is used to input a String data from the standardinput stream.
(t) State the output of the following program segment: (2012)
String s=“Examination”;
int n=s.length();
System.out.println(s.starts With(s.substring(5,n)));
System.out.println(s.charAt(2)==s.charAt(6));
(u) State the method that: (2012)
(i)Converts a string to a primitive float data type.
(ii)Determines if the specified character is an uppercasecharacter.
(w) State the data type and values of a and b afterthe following segment is executed. (2012)
String s1=“Computer”, s2=“Applications”;
a=(s1.compareTo(s2));
b=(s1.equals(s2));
(x) What will the following code output? (2012)
String s=“malayalam”;
System.out.println(s.indexOf(‘m’));
System.out.println(s.lastIndexOf(‘m’));
(y) Give the output of the following: (2011)
SGVP International School, Ahmedabad - INDIA Page11of25
S tring n=”Computer Knowledge”;
String m=”Computer Applications”;
System. out.println(n. substring(0,8). concat(m. substring(9)));
System.out.println(n.ends With(“e”));
(z) Write the output of the following : (2011)
(i) System.out.println(Character.isUpperCase(‘R’));
(ii) System.out.println(Character.toUpperCase(‘j’);
(aa) Write a statement each to perform the followingtask on a string : (2011)
(i) Find and display the position of the last spacein a string s.
(ii) Convert a number stored in a string variablex to double data type.
(ab) Write a statement each to perform the followingtask on a string :
(i) Find and display the position of the last spacein a string s.
(ii) Convert a number stored in a string variablex to double data type.
h : 5 U
C ser-defined Methods
(a) How are private members of a class differentfrom public members? (2018)
(b) rite a function prototype of the following:
W (2016)
A function PosChar which takes a string argument and a character argument and returns an
integer value.
(c) What is the function of catch block in exceptionhandling? Where does it appear in a program?
(2015)
( d) Differentiate between public and private modifiersfor members of a class. (2012)
(e) In the program given below, state the name andthe value of the (2012)
(i) method argument or argument variable
(ii) class variable
(iii) local variable
(iv) instance variable
(f) What are the two ways of invoking functions? (2011)
SGVP International School, Ahmedabad - INDIA Page12of25
h : 6 C
C lass as the Basis of all computation
(a) State the difference between call by value andcall by reference. (2019)
(b) Write the prototype of a function check whichtakes an integer as an argument and returns a
character. (2018)
(c) What are the two ways of invoking functions? (2017)
(d) Differentiate between formal parameter and actualparameter. (2016)
(e) What are the values of a and b after the followingfunction is executed, if the values passed are 30
and 50 : (2015)
void paws(int a, int b) {
a = a + b;
b = a – b;
a = a – b;
System.out.println(a + ” , ” + b);
}
(f) Consider the following class: (2014)
public class myClass{
public static int x = 3, y = 4;
public int a = 2, b = 3;
}
(i) Name the variables for which each object of theclass will have its own distinct copy.
(ii) Name the variables that are common to all objectsof the class.
h : 7
C onstructors
C
(a) Write two characteristics of a constructor. ( 2018)
(b) Differentiate between constructor and function. (2017)
(c) What is a parameterized constructor? (2016)
(d) Name the two types of constructors. (2015)
(e) What is a constructor? When is it invoked? (2014)
(f) Give a difference between a constructor anda method. (2013)
(g) Create a class with one integer instance variable.Initialize the variable using: (2012)
(i) default constructor.
(ii) parameterized constructor.
(h) (i) Name the package that contains Scannerclass. (2011)
(ii) Which unit of the class gets called, whenthe object of the class is created ?
(i) Explain the concept of constructor overloadingwith an example. (2011)
SECTION B (60 Marks)
ttempt any four questions from this Section.
A
The answers in this section should consist of the programs in either BlueJ environment or any program
environment with Java as the base.
Each program should be written using Variable descriptions/Mneumonic codes so that the logic of the
program is clearly depicted.
Flow-charts and algorithms are not required.
SGVP International School, Ahmedabad - INDIA Page13of25
h : 1 R
C evision of Class IX Syllabus
1. Use the switch case statement, write a menu drivenprogram to do the following: (2019)
(a) To generate and print letters from A to Z & their Unicode
A -
65
B -
66
. -
.
. -
.
Z -
90
(b) Display the following pattern iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
2. A tech number has a even number of digits if thenumber is split in two equal halves , then the
s quare of sum of these two halves is equal to the number itself. Write a program to generate and
print all 4 digit tech numbers: (2019)
Example:
Consider the number 3025
Square of sum of the halves of 3025
= (30 + 25)²
= (55)²
3025 is a tech number
3. Write a program to input a number and check andprint whether it is a Pronic number or not.
(Pronic number is the number which is the product of two consecutive integers) (2018)
Examples:
12 = 3 x 4
20 = 4 x 5
42 = 6 x 7
4. Write a program to accept a number and check anddisplay whether it is a spy number or not.
(A number is spy if the sum its digits equals the product of the digits.)
(2017)
Example: consider the number 1124 ,
s um of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 x 1 x 2 x 4=8
5. Using switch statement, write a menu driven programfor the following :
(2017)
(i) To find and display the sum of the series given below :
S = x1 -x2 + x2 – x4 + x5 – x20
(where x = 2)
SGVP International School, Ahmedabad - INDIA Page14of25
( ii) To display the following series :
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.
.
6 Using the switch statement, write a menu drivenprogram for the following: (2016)
(i) To print the Floyd’s triangle (Given below)
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
(ii) To display the following pattern:
I
I C
I C S
I C S E
For an incorrect option, an appropriate error message should be displayed.
7. Write a program to accept a number and check anddisplay whether it is a Niven number or not.
(Niven number is that number which is divisible by its sum of digits). (2016)
Example:
Consider the number 126.
Sum of its digits is 1+2+6 = 9 and 126 is divisible by 9.
8. Write two separate programs to generate the followingpatterns using iteration (loop) statements:
(a) (2015)
*
* #
* # *
* # * #
* # * # *
( b)
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
9. Using switch statement, write a menu driven programto: (2015)
(i) To find and display all the factors of a number input by the user ( including 1 and the excluding
the number itself).
Example:
Sample Input : n = 15
Sample Output : 1, 3, 5
(ii) To find and display the factorial of a number input by the user (the factorial of a non-negative
integer n, denoted by n!, is the product of all integers less than or equal to n.)
Example:
Sample Input : n = 5
SGVP International School, Ahmedabad - INDIA Page15of25
S ample Output : 5! = 1*2*3*4*5 = 120
For an incorrect choice, an appropriate error message should be displayed.
10. A special two-digit number is such that whenthe sum of its digits is added to the product of its
digits, the result is equal to the original two-digit number. (2014)
Example:
Consider the number 59.
Sum of digits = 5 + 9 = 14.
Product of its digits = 5 × 9 = 45.
Sum of the sum of digits and product of digits = 14 + 45 = 59.
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If
the value is equal to the number input, output the message “Special 2-digit number” otherwise,
output the message “Not a special 2-digit number”.
11. Using the switch statement, write a menu-drivenprogram to calculate the maturity amount of a
bank deposit. (2014)
The user is given the following options:
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept Principal (p), rate of interest (r) and time period in years (n). Calculate and
output the maturity amount (a) receivable using the formula a = p(1 + r / 100)n.
For option (ii) accept monthly installment (p), rate of interest (r) and time period in months (n).
Calculate and output the maturity amount (a) receivable using the formula a = p * n + p * n(n + 1) /
2 * r / 100 * 1 / 12.
For an incorrect option, an appropriate error message should be displayed.
12. The International Standard Book Number (ISBN)is a unique numeric book identifier which is printed
on every book. The ISBN is based upon a 10-digit code. The ISBN is legal if: 1 × digit1 + 2 × digit2 +
3 × digit3 + 4 × digit4 + 5 × digit5 + 6 × digit6 + 7 × digit7 + 8 × digit8 + 9 × digit9 + 10 × digit10 is
divisible by 11. (2013)
Example: For an ISBN 1401601499, sum = 1 × 1 + 2 × 4 + 3 × 0 + 4 × 1 + 5 × 6 + 6 × 0 + 7 × 1 + 8 × 4
+ 9 × 9 + 10 × 9 = 253 which is divisible by 11.
Write a program to:
(i) Input the ISBN code as a 10-digit integer.
(ii) If the ISBN is not a 10-digit integer, output the message “Illegal ISBN” and terminate the
program.
(iii) If the number is divisible by 11, output the message “Legal ISBN”. If the sum is not divisible by
11, output the message “Illegal ISBN”.
13. Using the switch statement, write a menu-drivenprogram: (2013)
(i) To check and display whether a number input by the user is a composite number or not. (A
number is said to be composite if it has one or more than one factor excluding 1 and the number
itself.). Example: 4, 6, 8, 9, …
(ii) To find the smallest digit of an integer that is input:
Sample Input: 6524
Output: Smallest digit is 2.
For an incorrect choice, an appropriate error message should be displayed.
14. Given below is a hypothetical table showing ratesof income tax for male citizens below the age of
65 years (2012)
SGVP International School, Ahmedabad - INDIA Page16of25
T axable Income (TI) in Rs Income Tax in Rs
Does not exceed Rs. 1,60,000 NIL
Is greater than Rs. 1,60,000 and less than or equal to Rs. 5,00,000. (TI – 1,60,000) x 10%
Is greater than Rs. 5,00,000 and less than or equal to Rs. 8,00,000 ((TI – 5,00,000) x 20%) +
34,000
Is greater than Rs. 8,00,000 ((TI – 8,00,000) x 30%) +
94,000
Write a program to input the age, gender (male or female) and Taxable Income of a person.
If the age is more than 65 years or the gender is female, display “wrong category”. If the age is less
than or equal to 65 years and the gender is male, compute and display the income tax payable as
per the table given above.
15. Using the switch statement, write a menu-drivenprogram to: (2012)
(i) Generate and display the first 10 terms of the Fibonacci series 0, 1, 1, 2, 3, 5, …
The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the
previous two.
(ii) Find the sum of the digits of an integer that is input.
Sample Input: 15390
Sample Output: Sum of the digits = 18.
For an incorrect choice, an appropriate error message should be displayed.
16. Write a program to input a number and print whetherthe number is a special number or not.
(A number is. said to be a special number, if the sum of the factorial of the digits of the number is
s ame as the original number).
Example : 145 is a special number, because 1!+4!+5! = 1 + 24 + 120 = 145 (Where ! stands for
factorial of the number and the factorial value of a number is the product of all integers from 1 to
that number, example 5! = 1*2*3*4*5 = 120) (2011)
17. Write a menu driven program to perform the following:(Use switch-case statement) (2011)
(a) To print the series 0, 3, 7, 15, 24, …… n terms (value of ‘n’ is to be an input by the user).
(b) To find the sum of the series given below :
S = 1/2 + 3/4 + 5/6 + 7/8 + ……… 19/20.
Ch : 3 Arrays
1. Write a program to input 15 integer elements inan array and sort them in ascending order using
the bubble sort technique. (2019)
.
2 Write a program to accept name and total marksof N number of students in two single subscript
array name() and totalmarks(). (2018)
Calculate and print:
The average of the total marks obtained by N number of students.
(average = (sum of total marks of all the students)/N)
Deviation of each student’s total marks with the average.
(deviation = total marks of a student – average)
3. Write a program to input integer elements intoan array of size 20 and perform the following
operations: (2017)
Display the largest number from the array.
Display the smallest number from the array.
Display sum of all the elements of the array.
SGVP International School, Ahmedabad - INDIA Page17of25
4. rite a program to input forty words in an array. Arrange these words in descending order of
W
alphabets, using selection sort technique. Print the sorted array. (2017)
5. Write a program to initialize the seven Wondersof the World along with their locations in two
different arrays. Search for a name of the country input by the user. If found, display the name of the
country along with its Wonder, otherwise display “Sorry Not Found!”. (2016)
Seven wonders — CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL OF CHINA,
MACHU PICCHU, PETRA, COLOSSEUM
Locations — MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example — Country Name: INDIA Output: INDIA-TAJMAHAL
Country Name: USA Output: Sorry Not Found!
6. Write a program to input and store roll numbers,names and marks in 3 subjects of n number of
s tudents in five single dimensional arrays and display the remark based on average marks as given
below: (2015)
verage Marks
A Remark
85 — 100 Excellent
75 — 84 Distinction
60 — 74 First Class
40 — 59 Pass
Less than 40 Poor
7. Write a program to input twenty names in an array.Arrange these names in descending order of
letters, using the bubble sort technique. (2015)
8. Write a program to accept the year of graduationfrom school as an integer value from the user.
Using the binary search technique on the sorted array of integers given below, output the
message “Record exists” if the value input is located in the array. If not, output the message
“Record does not exist” (2014)
{1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010}
9. Write a program to input 10 integer elementsin an array and sort them in descending order
using bubble sort technique. (2013)
10. Write a program to accept the names of 10cities in a single dimension array and their STD
(Subscriber Trunk Dialing) codes in another single dimension integer array. Search for a name of a
city input by the user in the list. If found, display “Search successful” and print the name of the city
along with its STD code, or else display the message “Search unsuccessful, no such city in the
list”. (2012)
11. Write a program to input and store the weightof ten people. Sort and display them in descending order
using the selection sort technique. (2011)
h : 4 String Handling
C
1. Write a program to input a sentence and convertit into uppercase and count and display the total
no. of words starting with a letter ‘A’. (2019)
Example:
SGVP International School, Ahmedabad - INDIA Page18of25
S ample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER
CHANGING
Sample Output: Total number of word Starting with letter ‘A’= 4
2. Write a program in Java to accept a string inlower case and change the first letter of every word
to upper case. Display the new string. (2018)
Sample input: we are in cyber world
Sample output: We Are In Cyber World
3. Write a menu driven program to display the patternas per user’s choice. (2018)
Pattern 1
ABCDE
ABCD
ABC
AB
A
Pattern 2
B
LL
UUU
EEEE
For an incorrect option, an appropriate error message should be displayed.
4. Special words are those words which starts andends with the same letter. (2016)
Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice versa
Examples:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes. Write a program to
accept a word check and print Whether the word is a palindrome or only special word.
5. Write a program that encodes a word into Piglatin.To translate word into Piglatin word, convert the
word into uppercase and then place the first vowel of the original word as the start of the new word
along with the remaining alphabets. The alphabets present before the vowel being shifted towards
the end followed by “AY”.
(2013)
Sample Input 1: London
Output: ONDONLAY
Sample Input 2: Olympics
Output: OLYMPICSAY
6. Write a program to accept a string. Convert thes tring to uppercase. Count and output the number
of double letter sequences that exist in the string. (2012)
SGVP International School, Ahmedabad - INDIA Page19of25
S ample Input: “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE”
Sample Output: 4
7. Write a program to accept a word and convert itinto lowercase if it is in uppercase, and display the
new word by replacing only the vowels with the character following it : (2011)
Example :
Sample Input : computer
Sample Output : cpmpvtfr
h : 6 C
C lass as the Basis of all computation
1. Design a class RailwayTicket with following description: (2018)
Instance variables/data members:
String name — To store the name of the customer
String coach — To store the type of coach customer wants to travel
long mobno — To store customer’s mobile number
int amt — To store basic amount of ticket
int totalamt — To store the amount to be paid after updating the original amount
Member methods:
void accept() — To take input for name, coach, mobile number and amount.
void update() — To update the amount as per the coach selected (extra amount to be added in the
amount as follows)
Type of Coaches Amount
First_AC 700
Second_AC 500
Third_AC 250
s leeper None
v oid display() — To display all details of a customers uch as name, coach, total amount and mobile
number.
Write a main method to create an object of the classand call the above member methods.
.
2 Define a class Electric Bill with the following specifications: (2017)
class: ElectricBill
Instance Variable/ data member:
String n – to store the name of the customer
int units – to store the number of units consumed
double bill – to store the amount to paid
Member methods:
Void accept()– to accept the name of the customerand number of units consumed
Void calculate()– to calculate the bill as per thefollowing tariff :
Number of units Rate per unit
SGVP International School, Ahmedabad - INDIA Page20of25
First 100 units Rs. 2.00
Next 200 units Rs. 3.00
Above 300 units Rs. 5.00
surcharge of 2.5% charged if the number of units consumed is above 300 units.
A
Void print()– To print the details as follows :
Name of the customer ………
Number of units consumed ……
Bill amount …….
Write a main method to create an object of the class and call the above member methods.
3. Define a class named BookFair with the following description: (2016)
Instance variables/Data members :
String Bname — stores the name of the book
double price — stores the price of the book Member methods :
(i) BookFair() — Default constructor to initialize data members
(ii) void Input() — To input and store the name and the price of the book.
(iii) void calculate() — To calculate the price after discount. Discount is calculated based on the
following criteria.
Price Discount
Less than or equal to Rs. 1000 2% of price
More than Rs. 1000 and less than or equal to Rs. 3000 10% of price
More than % 3000 15% of price
(iv) void display() — To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member methods.
4. Define a class called ParkingLot with the following description: (2015)
Instance variables/data members:
int vno — To store the vehicle number.
int hours — To store the number of hours the vehicle is parked in the parking lot.
double bill — To store the bill amount.
Member Methods:
void input() — To input and store the vno and hours.
void calculate() — To compute the parking charge at the rate of ₹3 for the first hour or part thereof,
and ₹1.50 for each additional hour or part thereof.
void display() — To display the detail.
Write a main() method to create an object of the class and call the above methods.
5. Define a class called Library with the followingdescription: (2012)
Instance variables/data members:
int accNum: stores the accession number of the book.
String title: stores the title of the book.
String auhor: stores the name of the author.
Member functions:
(i) void input(): to accept and store the accession number, title and author.
SGVP International School, Ahmedabad - INDIA Page21of25
( ii) void compute(): to accept the number of days late, calculate and display the fine charged at the
rate of Rs. 2 per day.
(iii) void display(): to display the details in the following format:
Accession Number Title Author
Write a main() method to create an object of the class and call the above member functions.
6. Define a class called mobike with the followingdescription: (2011)
Instance variables /data members:
int bno — to store the bike’s number
int phno — to store the phone number of the customer
String name — to store the name of the customer
int days — to store the number of days the bike is taken on rent
int charge — 4 calculate and store the rental charge
Member methods:
void input() — to input and store the detail of the customer
void compute() — to compute the rental charge.
The rent for a mobike is charged on the following basis:
First five days Rs. 500 per day.
Next five days Rs. 400 per day.
Rest of the days Rs. 200 per day.
void display() — to display the details in the following format:
h : 7 C
C onstructors
1. Design a class name ShowRoom with the followingdescription: (2019)
Instance variables/data members:
String name: to store the name of the customer.
long mobno: to store customer’s mobile number.
double cost: to store the cost of the item purchased.
double dis: to store the discount amount.
double amount: to store the amount to be paid after discount.
Methods:
ShowRoom(): default constructor to initialize thedata members
void input(): to input customer name, mobile number, cost
void calculate(): to calculate discount on the cost of purchased items, based on the following
criteria
Cost Discount(In percentage)
Less than or equal to ₹ 10000 5 %
More than ₹ 10000 and less than or equal to ₹ 20000 10 %
More than ₹ 20000 and less than or equal to ₹ 35000 15 %
SGVP International School, Ahmedabad - INDIA Page22of25
More than ₹ 35000 20%
v oid display()- To display customer, mobile number,amount to be paid after discount.
Write a main() method to create an object of the class and call the above methods.
2. Design a class to overload a function series()as follows: (2019)
(i) void series(int x, int n) – To display the sum of the series given below:
x¹+x²+x³+. . . . .x^n terms</b
(ii)void series(int p) – To display the following series
0, 7, 26, 63. . . . .p terms
(iii) void series() – To display the sum of the series given below:
1/2+1/3+1/4+. . . . . .1/10
3. Design a class to overload a function volume()as follows: (2018)
(a) double volume (double R) – with radius (R) as an argument, returns the volume of sphere using
the formula.V = 4/3 x 22/7 x R3
(b) double volume (double H, double R) – with height(H) and radius(R) as the arguments,
returns the volume of a cylinder using the formula.
V = 22/7 x R2 x H
(c) double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H)
as the arguments, returns the volume of a cuboid using the formula.
V = L x B x H
4. Design a class to overload a function check() asfollows: (2017)
i) void check(String str, char ch) – to find and print the frequency of a character
in a string.
Example : Input — Output
Str = “success” number of s present is = 3
ch = ‘s’
ii) void check (String s1) – to display only vowels from string s1, after converting it to lowercase.
Example : Input: S1= “computer”
output: o u e
5. Design n class to overload a function SumSeriesOas follows: (2016)
(i) void SumSeries(int n, double x) – with one integer argument and one double argument to find
and display the sum of the series given below:
( ii) void SumSeries() – To find and display the sum of the following series:
s = 1 + (1 x 2) + (1 x 2 x 3) + ….. + (1 x 2 x 3 x 4 x 20)
6. Design a class to overload a function Joystring() as follows: (2015)
(a) void Joystring(String s, char ch1, char ch2) with one string argument and two character
arguments that replaces the character argument ch1 with the character argument ch2 in the
given String s and prints the new string.
(b) Example:
Input value of s = "TECHNALAGY"
ch1 = 'A'
ch2 = 'O'
Output: "TECHNOLOGY"
SGVP International School, Ahmedabad - INDIA Page23of25
(c) void Joystring(String s) with one string argument that prints the position of the first space
and the last space of the given String s.
Example:
Input value of s = "Cloud computing means Internet based computing"
Output:
First index: 5
Last Index: 36
(c) void Joystring(String s1, String s2) with two string arguments that combines the two strings
with a space between them and prints the resultant string.
Example:
Input value of s1 = "COMMON WEALTH"
Input value of s2 = "GAMES"
Output: COMMON WEALTH GAMES
(Use library functions)
7. Define a class named MovieMagic with the followingdescription: (2014)
Instance variables/data members:
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 (min. rating = 0.0 and max. rating = 5.0)
Member Methods:
MovieMagic(): default constructor to initialize numeric data members to 0 and String data member
to “”.
void accept(): to input and store year, title and rating.
void display(): to display the title of a movie and a message based on the rating as per the table
below:
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
Write a main method to create an object of the class and call the above member methods.
8. Design a class to overload a function area() asfollows: (2014)
(i) double area(double a, double b, double c) with three double arguments, returns the area of a
s calene triangle using the formula:
area = √(s(s – a)(s – b)(s – c))
where s = (a + b + c) / 2.
(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a trapezium
using the formula:
area = 1/2 × height × (a + b)
(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns the area
of a rhombus using the formula:
area = 1/2 × (diagonal1 × diagonal2)
9. efine a class named FruitJuice with the followingdescription:
D (2013)
Instance variables/data members:
SGVP International School, Ahmedabad - INDIA Page24of25
int productCode: stores the product code number.
String flavour: stores the flavour of the juice (e.g. orange, apple, etc.).
String packType: stores the type of packaging (e.g. tetra-pack, PET bottle, etc.).
int packSize: stores package size (e.g. 200ml, 400ml, etc.).
int productPrice: stores the price of the product.
Member functions:
(i) FruitJuice(): default constructor to initialize integer data members to 0 and String data members
to “”.
(ii) void input(): to input and store the product code, flavour, pack type, pack size and product price.
(iii) void discount(): to reduce the product price by 10.
(iv) void display(): to display the product code, flavour, pack type, pack size and product price.
10. Design a class to overload a function series()as follows:
(i) double series(double n) with one double argument and returns the sum of the series, sum = 1 / 1
+ 1 / 2 + 1 / 3 + … + 1 / n.
(ii) double series(double a, double n) with two double arguments and returns the sum of the series,
s um = 1 / a2 + 4 / a5 + 7 / a8 + 10 / a11 + … to n terms. (2013)
11. Design a class to overload a function polygon()as follows: (2012)
(i) void polygon(int n, char ch): with one integer argument and one character argument that draws a
filled square of side n using the character stored in ch.
(ii) void polygon(int x, int y): with two integer arguments that draws a filled rectangle of length x and
breadth y, using the symbol ‘@’.
(iii) void polygon(): with no arguments that draws a filled triangle shown below.
Example:
(i) Input value of n = 2, ch = ‘O’
Output:
OO
OO
(ii) Input value of x = 2, y = 5
Output:
@@@@@
@@@@@
(iii) Output:
*
**
***
12. Design a class to overload a function comparedas follows : (2011)
(a) void compare(int, int) — to compare two integer values and print the greater of the two integers.
(b) void compare(char, char) — to compare the numeric value of two characters and print the
character with higher numeric value.
(c) void compare(String, String) — to compare the length of the two strings and print the longer of
the two.
SGVP International School, Ahmedabad - INDIA Page25of25