Practical
Practical
QUESTION 1:
A cloth showroom has announced the following
festival discounts on the purchase of items based on
the total cost of the items purchased:
Total cost Discount (in percentage)
Rs.2000 5%
Rs.2001 to Rs.5000 25%
Rs.5001 to Rs.10000 35%
Above Rs.10000 50%
Write a Java program to input the total cost. Compute
and display the amount to be paid by rhe customer
after availing the discount.
Question-2:
Using switch-case statement ,write a menu driven
program to calculate and display the area of the
following-
1. Area of a circle (pi*r*r*where pi=3.14)
2. Area of Square (side*side)
3. Area if rectangle(length*breadth)
Question-3:
Using switch-case statement ,write a menu driven
program to calculate and display the area of the
following-be
A. Volume of a cube (s*s*s)
B. Volume of a sphere (4/3*pi*r*r*r where
pi=3.14)
C.Volume of cuboid (l*b*h)
QUESTION 4:
Using the switch-case statement, write a menu
driven Java program for the following:
(i)To print the Floyd’s triangle
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
QUESTION 5:
Write a Java program to input a number and check
whether it is an Automorphic number or not.
A number itself is called an automorphic number if
and only if the square of the given number ends with
the number itself.
For example,25,76 are automorphic numbers because
their square is 625 and 5776,respectively and the last
two digits of the square represent the number itself.
QUESTION 6:
Design a class to overload a function compare as
follows:
(i) void compare(int ,int ) – To compare two
integer value and print the greater value of
them.
(ii) void compare (char,char)- To compare the
numeric value of two characters and print the
character with higher value.
(iii) void compare (String,String)- To compare the
length of two strings and print the longer of
them.
QUESTION-7:
Define a class to accept values into an array of
double type of size 20.Accept a double type value
from user and search in the array using Linear
Search method. If value is found display message
“Found” with its position where it is present in the
array. Otherwise display message “Not found”.
QUESTION-8:
Write a Java program to perform Binary search on a
list of ten integers given below ,to search for an
element input any number by the user. If the
number is found in an array then display the
element along with its position, otherwise display
the message “Search element not found”.
QUESTION-9:
Write a Java program to input and store 10
character values in a single dimensional Array. Sort
and display them in descending order by using the
Bubble sort technique.
QUESTION-10:
Write a Java program to accept 10 different
numbers in a single dimensional integer Array.
Arrange the number in ascending order by using the
Selection Sort technique and display the elements of
array after sorting.
QUESTION-11:
Write a Java program to create a single dimensional
integer array and store 20 elements in it. Print all
the buzz numbers present in the array.
(Buzz number is a number that is divisible by 7 or has
the last digit as 7
Example: 57 is a buzz because the number ends with
seven. Another example is 28 because the number is
divisible by seven.).
QUESTION-12:
Write a Java program to create three single
dimensional double type of arrays to store marks of
physics, chemistry and maths of 30 students (the
maximum marks are 100 for each subject). Count and
print the number of students obtained 80% and above
in aggregate.
QUESTION-13:
Write a Java program to create single dimensional
integer array to store 10 different numbers. Print the
greatest and smallest element of the array.
QUESTION-14:
Write a Java program to declare a square matrix M [n]
[n], where n is taken from the user. Calculate the
following :
1.Print array in matrix form .
2. Print the sum of all elements of the double
dimensional array.
Input:
n=3
1
2
3
4
5
6
7
8
9
Matrix:
1 2 3
4 5 6
7 8 9
Output:
Sum of all elements:45
QUESTION-15:
Write a Java program to input and store elements in a
double dimensional array of size 3*3 and find the sum
of each row separately.
Example:
Input:
2 1 5
8 6 9
3 7 4
Output :
Sum of first row = 8
Sum of second row = 23
Sum of third row = 14
QUESTION-16:
Define a class to accept a String from the user. Count
and print the number of digits, alphabets and special
characters in the string.
Example:
S= “KAPILDEV@83”
Output: Number of digits -2
Number of Alphabet – 8
Number of Special Characters – 1
QUESTION-17:
Write a Java program to enter a string in uppercase.
Count, print and replace all the vowels present in the
string with Asterisk(*) symbol.
Example:
Input: COMPUTER
Output: No of vowels in string is – 3
C*MP*T*R
QUESTION-18:
Write a Java program to enter a string in capital
letters. Print the string in alphabetical order of its
letters.
Example:
Input : COMPUTER
Output: CEMOPRTU
QUESTION-19:
Write a Java program to input Customer name and
Electricity unit consumed by the customer. Calculate
and display the total bill amount to be paid by the
customer as per the following slabs.
Number of unit consumed Rate per unit
First 100 units. Rs. 450 Rental charge.
Next 100 calls. Rs. 1.50 per unit+ Rental
Charge.
Next 100 calls. Rs. 2.50 per unit+ Rental
Charge.
Above 300 calls. Rs. 3.00 per unit+ Rental
Charge.
QUESTION-20:
A tech number has an even number of digits. If the
number is split in two equal halves, then the square of
sum of these halves is equal to the number itself.
Write a Java program to generate and print all four
digits tech numbers.
Example :
Consider the number 3025
Square of sum of the halves of 3025 =
(30+25)square
=(55)square
=3025
Hence, 3025 is a tech Number.