Week 0.1 - Assignments
Week 0.1 - Assignments
1. Accept a char input from the user and display it on the console.
2. Accept two inputs from the user and output its sum.
Number 1 Integer
Number 2 Float
Sum Float
a. The program should accept 3 inputs from the user and calculate simple interest
for the given inputs. Formula: SI=(P*R*n)/100)
4. Write a program to check whether a student has passed or failed in a subject after
he or she enters their mark (pass mark for a subject is 50 out of 100).
a. The program should accept input from the user and output a message as
“Passed” or “Failed.”
mark float
5. Write a program to show the grade obtained by a student after they enter their total
mark percentage.
a. The program should accept input from the user and display their grade as
follows
Mark Grade
> 90 The program
80-89 B
70-79 C
60-69 D
50-59 E
< 50 Failed
6. Using the ‘switch case,’ write a program to accept an input number from the user
and output the day as follows.
Input Output
1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday
7 Saturday
E.g.:
Input: 5
Output:
1x5=5
2 x 5 = 10
3 x 5 = 15
4 x 5 = 20
5 x 5 = 25
6 x 5 = 30
7 x 5 = 35
8 x 5 = 40
9 x 5 = 45
10 x 5 = 50
8. Write a program to find the sum of all the odd numbers for a given limit
a. Program should accept an input as limit from the user and display the sum
of all the odd numbers within that limit
Input: 10
9. Write a program to print the following pattern (hint: use nested loop)
12
123
1234
12345
Input: 5
Input: 5
Input: 5
Input: MALAYALAM
Input: HELLO
Input: 3
Input:
123
456
789
Input:
10 20 30
40 50 60
70 80 90
11 22 33
44 55 66
77 88 99
15. Write a program to accept an array and display it on the console using functions
a. Program should contain 3 functions including main() function
main()
1. Declare an array
2. Call function getArray()
3. Call function displayArray()
getArray()
displayArray()
16. Write a java program to check whether a given number is prime or not
a. Program should accept an input from the user and display whether the
number is prime or not
Input: 7
17. Write a menu driven java program to do the basic mathematical operations such as
addition, subtraction, multiplication and division (hint: use if else ladder or switch)
a. Program should have 4 functions named addition(), subtraction(),
multiplication() and division()
b. Should create a class object and call the appropriate function as user prefers
in the main function
18. Grades are computed using a weighted average. Suppose that the written test
counts 70%, lab exams 20% and assignments 10%.
Written test = 81
Lab exams = 68
Assignments = 92
Write a program to find the grade of a student during his academic year.
a. Program should accept the scores for written test, lab exams and
assignments
b. Output the grade of a student (using weighted average)
Eg:
Written test = 55
Lab exams = 73
Assignments = 87
Eg 1:
Enter the annual income
495000
Income tax amount = 24750.00
Eg 2:
Enter the annual income
500000
Income tax amount = 25000.00
20. Write a program to print the following pattern using for loop
2 3
4 5 6
7 8 9 10
21. Write a program to multiply the adjacent values of an array and store it in an
another array
a. Program should accept an array
b. Multiply the adjacent values
c. Store the result into another array
Eg:
1 2 3 4 5
Output
2 6 12 20
main()
getArray()
getArray()
displayArray()
Eg:
Enter the size of array
1 2
3 4
5 6
7 8
Output:
6 8
10 12
23. Write an object oriented program in java to store and display the values of a 2D
array
a. Program should contains 3 functions including the main function
main()
1. Declare an array
2. Call function getArray()
3. Call function displayArray()
getArray()
1. Get values to the array
displayArray()
Eg:
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9
24. Write a menu driven program in java to calculate the area of a given object.
a. Program should contain two classes
i. Class 1: MyClass
ii. Class 2: Area
b. Class MyClass should inherit class Area and should contain the following
functions
i. main()
ii. circle()
iii. square()
iv. rectangle()
v. triangle()
c. Class Area should contain the following functions to calculate the area of
different objects
i. circle()
ii. square()
iii. rectangle()
iv. triangle()
circle() {
square() {
rectangle() {
triangle() {
}
}
Class Area{
circle(){
square(){
rectangle() {
triangle() {
Eg 1:
1. Circle
2. Square
3. Rectangle
4. Triangle
Output
Eg 2:
1. Circle
2. Square
3. Rectangle
4. Triangle
Output