STD X Assignments
STD X Assignments
Program 1
Create a class in Java as Swap_numbers to accept two integer values from user as
‘num1’ and ‘num2’. Write a function to exchange the values of ‘num1’ and ‘num2’
using call by reference.
Instance variables : num1, num2 to accept integer values from user.
Methods : void swap(Swap_numbers sn) to interchange num1 and num2 values.
Program 2
Write a program in Java to check if the given number is Armstrong number. Any
number is called as Armstrong number if sum of cube of all the digits of the given
number is equal to the given number. Eg: 370 = 33 + 73 + 03 hence, 370 is an
Armstrong number.
Program 3
Write a program to print first 10 numbers in the Fibonacci series.
Eg: 0, 1, 1, 2, 3, 5,…..
Program 4
Using the switch statement, write a menu driven program to:
(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
Program 5
Write a program to accept the names of 10 cities in a single dimension string array and
their STD (Subscribers 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’.
Program 6
Write a Java program to perform basic Calculator operations using switch-case.
When you think about a calculator, operations like addition, subtraction,
multiplication, and division comes into the mind. Let’s implement the basic calculator
operations with the help of the below program.
Program 7
Write a Java program to find out whether the given String is Palindrome or not.
A palindrome is a number, string or a sequence which will be the same even after you
reverse the order. For example, RACECAR, if spelled backward will be same as
RACECAR.
Program 8
Write a program in Java to print a Diamond Pattern as follows.
*
**
***
****
*****
****
***
**
*
Program 9
Write a Java Program to find the Transpose of a given Matrix.
Transpose of a matrix is obtained by changing rows to columns and columns to rows.
In other words, transpose of A[][] is obtained by changing A[i][j] to A[j][i].
Program 10
Write a Java program to define an integer array of size 10. Accept array elements from
user and display them. Sort the array using selection sort algorithm and display the
sorted array.
Program 11
Write a Java program to define an integer array of size 10. Accept array elements from
user and display them, accept a integer value from user and check if this value is
present in the array. If value is found then display “Found” along with the index of the
value, else print “Not Found”. Use Binary search for finding value in array.
Program 12
A parking garage charges Rs. 25.00 minimum fee to park for up to three hours. The garage
charges an additional Rs. 10.00 per hour for each hour or part thereof in excess of three
hours. The maximum charge for any given 24 hour period is Rs.150.00
Assume that no car parks for longer than 24 hours at a time.
Write a Java program that calculates and displays the parking charges for each customer who
parked in the garage yesterday.
Input the number of hours parked for each customer. The number of customers can be fixed
using a final constant.
The program should display the charge for each customer and should calculate and display
the running total of the day's receipts.
Use a method called calculateCharges to determine the charge for each customer.
Program 13
Write a program to input electricity unit charges and calculate total electricity bill according
to the given condition:
• For first 50 units Rs. 0.50/unit
• For next 150 units Rs. 0.75/unit
• For next 250 units Rs. 1.20/unit
• For unit above 450 Rs. 1.50/unit
• An additional surcharge of 20% is added to the bill
Program 14
Write a program in Java to accept marks of 5 subjects for 20 students. Write a method to
calculate total of all 5 subjects and average marks secured by each student. Also display the
stream each student should select based on the following criteria on average marks secured.