Assignment
Assignment
Instructions:
1. Part 1: Java Basics
Write a Java program to perform the following tasks:
a. Declare and initialize variables of different types (int, double, char, String).
b. Perform basic arithmetic operations (addition, subtraction, multiplication,
division) with two integers and print the results.
c. Use a conditional statement (if-else) to check whether a given integer is even or
odd.
d. Write a method that takes two integers as input, adds them, and returns the
result. Print the result in the main method.
2. Part 2: Control Structures and Loops
Write a Java program to:
a. Print all numbers from 1 to 10 using a for loop.
b. Write a program that uses a while loop to print the squares of numbers from 1 to
5.
c. Create a program that uses a do-while loop to print the first 5 numbers in the
Fibonacci sequence.
d. Use a switch-case statement to display the name of the day based on a number
input (1 for Monday, 2 for Tuesday, etc.).