s9.
JUsing switch statement, write a menu driven program for the
following.
(a) To find and display the sum of the series given below:
S=x- x² + x3- +5
(b) To fnd and display the sum of the series given below:
1 1 1 1
S=+ + + to n terms
A.)Write a program to accept a number and check whether it is aSpy Number or not
(A number is spy if the sum of its digits equals the product of its digits.)
For exanmple,
Sample Input: 1124
Sum of the digits = 1+ 1+2 + 4 = 8
Product of the digits = 1*1*2*4 = 8 [ICSE 201]
11Using the switch statement, write a menu driven program for the following:
[ICSE 2016]
(a) To print the Floyd's triangle: (b) To display the following pattern:
1
2 3 IC ’
4 5 6 ICS
7 8 9 10 ICS E
ulint=
11 12 13 14 15
For an incorrect option, an appropriate error message should be displayed.
patterns:
124 Write a program in Java to display the following
(b) ZYXWw
(a) A
ab 2 ZYXW
ABC 3 ZYX
abcd y ZY
ABCDES Z
and negative numbers)
3Write a program in Java to store 10 numbers (including positive numbers followed by
negative
in a Single Dimensional Array (SDA). Display all the
the positive numbers.
Sample Input:
n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
15 21 -32 -41 54 61 71 -19 -44 52
Sample Output: -32, -41, -19, -44, 15, 21, 54, 61, 71, 52
IISt OI 1 S.
Hint: Class average is the average marks obtained by 40 students in a particular subject.
8. Write a program in Java to accept 20 numbers in a single dimensional array ar[201.
Transfer and store all the even numbers in an array even[ ]and all the odd numbers
in another array odd[ |. Finally, print the elements of both the arrays.
15. A double dimensional array is defined as N[4][4] to store numbers. Write a prograrm
nree
to find the sum of all even numbers and product of all odd numbers of the clorn
stored in Double Dimensional Array (DDA).
Sample Input:
12 10 15 17
30 11 32 71
17 14 29 31
41 33 40 51
19. If arraysMand M+N are as shown below, write aprogram in Java to find the array
N. [ICSE 2004]
|-1 0 2 -6 9 4
M =
-3 -1 6 M + N =|4 5 0
4 3 -1| 1 -2 -3
16. Write a program to input a sentence. Count and display the frequency of each letter
of the sentence in alphabetical order.
Sample Input: COMPUTER APPLICATIONS [ICSE 2010]
Sample Output:
Character Frequency Character Frequency
A 2 2 Coy,16e
C 2 P 3
I 1 R 1
L 2 S 1
M 1 T 2
N 1 U 1
17. Write a program to accept a string. Convert the string into uppercase letters. Count
and output the number of double letter sequences that exist in the string
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE"
Sample Output: 4 (ICSE 2012]
28. Write a program in Java toinput the names of 10 cities in a Single Dimensional Array.
Display only those names which begin with a consonant but end with a vowel.
Sample Input: Kolkata, Delhi, Bengaluru, Jamshedpur, Bokaro,
Sample Output: Kolkata
Delhi |2
Bengaluru )2
Bokaro 2
2
names and their capitals in two
25. Write a program in Java to store 10different country
different Single Dimensional Arrays (SDA). Display the country
names (that starts with
avowel) along with their capitals in the given format.
Country Names Capital
X X X X X X X X
X X X X X X X X
str). The
8. Write aprogram in Javva to accept a word. Pass it to a mnethod Magic(String
two letters are
method checks the String for the presence of consecutive letters. If
consecutive at any position then the method prints "It is a Magic String", otherwise
it
prints "It is not a Magic String".
Sample Input: computer
Sample Output: It is not a Magic String
Sample Input: DELHI
Sample Output: It is a Magic String
19. Design a class to overload a method compare( ) as follows:
() void compare(int, int) : to compare two integers values and print the
greater of the two integers.
two characters
(ii) void compare(char, char) : to compare the nummeric value of value.
and print with the higher numeric
two strings and
: to compare the length of the
(iii) void compare(String, String) print the longer of the two.
[ICSE 2011]
Design aclass to overload the method display(......) as follows:
21. checks and prints whether the number is a
(i) void display(int num) :
perfect square or not.
word str COntains the
(ii) void display(String str, char ch) : checks and prints if the
letter ch or not.
(i) void display(String str) : checks and print the number of special
characters present in the word str.
Write asuitable main( ) method.
16. Define a class called ParkingLot with the following description:
Class name : ParkingLot
Instance variables/Data members:
int vno : to store the vehicle number
parking
int hours : to store the number of hours the vehicle is parked in the
lot
double bill : to store the bill amount
Member methods:
void input( ) : to input the vno and hours
compute the parking charge at the rate 3 for the first hour
void calculate() : to for each additional hour or part
or the part thereof and ? 1.50
thereof.
e uses
void display( ) : to display the detail the above methods.
to create an object of the class and call
Write a main method [ICSE 2015]
An electronics shop has announced a special discount on the purchase of laptops as
given below:
Category Discount on Laptop
Up to 25,000 5.0%
25,001 - 50,000 7.5%
the
the 50,001 1,00,000 10.0%
ault More than 1,00,000 15.0%
One
Define a class Laptop described as follows:
Data members/ Instance variables:
name, price, dis, amt;
Member Methods:
the data menmbers
wt () a parameterised constructor to initialize
the price)
ther?
(i) to accept the details (name of the customer and
(1) to compute the discount to be paid after discount.
(iv) to display the name, discount and amnount
class and call the member methods.
Write a main method to create an object of the
K Define a class Bill that calculates the telephone bill of a consumer with the following
description:
Instance variables/Data members:
int bno : bill number
String name : name of Consumer
-tring
int callI : no. of calls consumed in amonth
pack double amt : bill amount to be paid by the person
Member Methods
value
with default initial
Bill() : constructor to initialize data members
accept billno, name and no. of calls
Bill(...) : parameterised constructor to
Consumed.
Constructors 421
Calculate) : to calculate the monthly telephone bill for
a consumer as per the foll
condition
Units consumed Rate
First 100 calls 0.60/ call
Next 100 calls 0.80/ call
Next 100 calls 1.20/ call
Above 300 calls 1.50/ call
Fixed monthly rental applicable to all consumers: ? 125
Display() : to display the details
Create an object in the main) method and invoke the above functions to perform #
desired task.
description:
12. Definea class called BookFair with the following
Instance variables/Data members:
String Bname : stores the name of the book
double price : stores the price of the book
Member Methods:
(1) BookFair( ) : constructor to initialize data memberS
(iü) void input( ) :to input and store the name and price of the book
(iü) void calculate( ) : to calculate the price after discount. Discount is calculae
based on the following criteria:
Price Discount
Less than or equal to 1000 2% of price
More than 1000 and less than or equal to ? 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 membe
methods. ICSE 2016
4*4 matrix in a
Prog. 13 Write a program in Java to store the numbers in a
lowest numbers of
Double Dimensional Array. Find the highest and the
the matrix by using an input statement.
Sample Input:
The numbers of the matrix are
12 21 13 14
24 41 51 33
61 11 30 29
59 82 41 76
Sample Output:
The lowest number in the array is 11
The greatest number in the array is 82
Prog. 14 Write a program in Java to store the numbers in a 4*4 matrix in a
Double Dimensional Array. Find the transpose of the matrix by using
an assignment statement. The transpose of a matrix is obtained when we
change the row elements into column and column elements into rows.
Sample Input:
The numbers of the matrix are:
12 21 13 14
24 41 51 33
61 11 30 29
59 82 41 76
Sample Output:
The transpose of the matrix is:
12 24 61 59
21 41 11 82
1351 30 41
14 33 29 76