Practical Assignment
1.
Write a Java
program to calculate the area of a rectangle. (Area = length
* breadth Given length = 5, and breadth = 4)
2.
Write a Java
program to calculate the volume of a cylinder. (Volume = πr2h
Given r= 5.5, h= 6.5)
3.
Write a program
in Java to find the area, perimeter, and diagonal of a square and display the
output of the program. (Given: side of a square = 25).
4.
Write a Java
program to input a number from the user and check and display whether it is an even number or odd.
5.
Write a program in
Java to input the name and basic salary of an employee. Calculate and display the gross
salary and net salary when: da=
30% of basic
hra= 12.5% of basic
pf= 10% of basic
gross = basic + da + hra
net pay = gross – pf
6.
Write a program
in Java to input two numbers. Display the numbers after swapping them by using a
third variable.
Sample Input: a= 95, b=45
Sample Output: a=45, b-95
7. The time period of a Simple Pendulum is given by the
formula:T = 2π
Write a program to calculate and display the time
period of a Simple Pendulum by taking length (l) and acceleration due
to gravity (g) as inputs. [π=22/7]
8.
Write a program
to input a number. Calculate its square root and cube root. Finally, display the
result by rounding it off. Sample Input: 5
Square
root of 5= 2.2360679 Rounded form= 2
Cube root
of 5 = 1.7099759 Rounded form= 2
9. In an examination, the grades are awarded to the students in 'Science" according to the average marks obtained in the examination.
Marks |
Grades |
80% and above |
Distinction |
60% or more but less than 80% |
First Division |
45% or more
but less than 60% |
Second
Division |
40% or more
but less than 45% |
Pass |
Less than 40% |
Promotion not
granted |
Write a to input name and marks in Physics, Chemistry and Biology. Calculate the average marks. Display the name, average marks, and the grade obtained.
10. A cloth showroom has announced festival discounts and
gifts on the purchase of items, based on the total cost as givenbelow:
Total Cost Discount Gift
Up to 2,000 5% Calculator
2,001 to 5000 10% School
Bag
5,001 to 10,000 15% Wall
Clock
Above 10,000 20% Wrist
Watch
Write a program to input the total cost. Compute and
display the amount to be paid by the customer along with the gift.
11.
Using the switch
statement, write a menu-driven program:
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 factors 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
Sample output: Smallest digit is 2
For an incorrect choice, an appropriate error message
should be displayed.
12.
Write a program
to accept two angles. Calculate and display whether they are 'Complementary
Angles' or 'Supplementary Angles' as per the user's choice. [Hint:
Enter 'c' for complementary or 's' for supplementary]
13.
Write a Java
program to accept a number from the user and display the ‘factorial’
of the number entered by the user.
14.
Write a Java
program to input a number from the user and check and display whether it is a ‘Prime
number’ or not.
15.
Write a program
to accept a number and check whether it is a ‘Spy Number’ or not.
(A number is a spy if the sum of its digits equals the product of its digits.)
Sample Input: 1124
Sum of the digits=1+1+2+4=8 Product of the digits = 1*1*2*4 = 8
16.
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 the original two-digit
number.
Example: Consider the number 59.
Sum of digits=5+9=14 Product
of digits=59 450
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, then display the message "Special 2-digit number"
otherwise, display the message "Not a special two-digit number".
17.
Write a program
to input a number. Check and display whether it is a ‘Niven number’
or not. (A number is said to be Niven when it is divisible by the sum of its
digits).
Sample Input: 126 Sum of its digits=1+2+6=9 and 126 is
divisible by 9.
18.
Write a Java
program to display the first ten terms of the ‘Fibonacci series’.
19.
Write a Java
program to display the first ten terms of the series 1, 4, 9, 16, …… .
20.
Define a class
to overload
the method print( ) as follows:
void print ()-to print the format 1
2 3
456
7 8 9 10
boolean print (int n) - to check whether the number is a Dudeney number, a number is dudeney if the cube of the sum of the digits is equal to the number itself. Eg: 512 (5+1+2)3 = (8)3=512
void print (int a, char ch) - if ch = s or
S print the square of the number else if ch=c or C print the cube of the number.
21.
Design a class
to overload a function area( ) as follows:
i. double area (double a, double b, double c) with three
double arguments, returns the area of a scalene triangle using the formula:area
= 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 x diagonal2)
22.
Write a program
in Java to store 20 numbers (even and odd numbers) in a Single Dimensional Array
. Calculate and display the sum of all even numbers and all odd numbers
separately.
23.
Write a program
to input and sort the weight of ten people. Sort and display them in ascending
order using bubble sort technique.
24.
Define a class
to accept 10 integers and arrange them in descending order using bubble
sort. Print the original array and the sorted array.
25.
Define a class
to accept values into a double array of size 20 and print the
range of the array, range is the difference between the largest and the
smallest elements of the array.
26.
Write a program
to perform a binary search on a list of integers given below, to search for
an element input by the user. If it is found display the element along with its
position, otherwise display the message "Search element not found".
5, 7, 9, 11, 15, 20, 30, 45, 89, 97
27.
Write a program
to accept the names of 10 cities in a single-dimensional string array and their
STD (Subscribers Trunk Dialling) codes in another single dimension integer
array. Search for the 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". (Use linear Search technique for
searching the name of a city)
28.
Define a class
to accept the names of 10 students in an array and check for the existence of
the given name in the array using linear search, if found print
the position of the name, if not found print the appropriate message. Also
print the names which begins with the word "SRI".
29.
Write a program
to accept a word and convert it into lower case, if it is in upper case.
Display the new word by replacing only the vowels with the letter
following it.
Sample Input: computer
Sample Output: cpmpvtfr
30.
Define a class
to accept a string and print the same in reverse, also print the number
of vowels in the string.
Input : S="BEAUTIFUL"
Output "LUFITUAEB" No. of vowels = 5
31.
Write a program
that encodes a word into Piglatin. To translate the word into the 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 is shifted towards the end
followed by "AY".
Sample Input 1: London
Output: ONDONLAY
32.
Write
a program to input a sentence and convert it into uppercase and count and
display the total number of words starting with a letter 'A'.
Example:Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION
TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with letter 'A' = 4
33.
Write a program
to display the 'Abundant numbers’ from
10 to 100. An 'Abundant' number is a number for which the sum of its
proper divisors (excluding the number itself) is greater than the number
itself.
For example: take a number (say, 12)
Factors of 12= 1, 2, 3, 4, 6 Sum of factors= 1+2+3+4+6= 16
Since, 16>12, thus, 12 is an Abundant number.The
first few abundant numbers are 12, 18, 20, 24, 30, 36, 40,
34. Write a program in Java to display the given pattern.
54321
4321
321
21
1
35. Write a program to display the given pattern.
1
10
101
1010
10101
No comments:
New comments are not allowed.