You are on page 1of 10

### Homework 1: Simple Calculator

Create a Java program that adds two numbers entered by the user. Prompt the user to enter two
numbers and display the sum.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter the first number.

3. Prompt the user to enter the second number.

4. Calculate and display the sum of the two numbers.

5. Include appropriate messages for clarity.

6. Implement exception handling to address non-numeric inputs.

**Example:**

```

Welcome to the Simple Calculator!

Enter the first number: 5.2

Enter the second number: 3.8

The sum is: 9.0

```

### Homework 2: Even or Odd

Write a Java program that takes an integer input from the user and determines whether it's an even or
odd number. Display an appropriate message indicating the result.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter an integer.


3. Determine whether the entered number is even or odd.

4. Display a message indicating if the number is even or odd.

5. Include appropriate messages for clarity.

**Example:**

```

Welcome to the Even or Odd program!

Enter an integer: 7

7 is an odd number.

```

### Homework 3: Number Comparison

Implement a Java program that prompts the user to enter two numbers and compares them. Display
messages such as "Number 1 is greater," "Number 2 is greater," or "Both numbers are equal."

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter the first number.

3. Prompt the user to enter the second number.

4. Compare the two numbers and display appropriate messages.

5. Include appropriate messages for clarity.

**Example:**

```

Welcome to the Number Comparison program!

Enter the first number: 15

Enter the second number: 20

Number 2 is greater.
```

### Homework 4: Prime Number Checker

Write a Java program that takes an integer input from the user and determines whether it is a prime
number or not. Use a for loop to check for factors of the given number. Display an appropriate message
indicating whether the number is prime or not.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter an integer.

3. Check whether the entered number is prime using a for loop.

4. Display a message indicating if the number is prime or not.

5. Include appropriate messages for clarity.

6. Provide guidance on optimizing the prime-checking algorithm for efficiency.

**Example:**

```

Welcome to the Prime Number Checker!

Enter a number: 17

17 is a prime number.

```

### Homework 5: Guess the Number Game

Implement a number guessing game where the computer generates a random number between 1 and
100, and the user has to guess the number. Provide feedback to the user if their guess is too high or too
low. Use a loop to allow the user to keep guessing until they correctly identify the number.

**Instructions:**
1. Display a welcome message to the user.

2. Generate a random number between 1 and 100.

3. Prompt the user to guess the number.

4. Provide feedback if the guess is too high or too low.

5. Allow the user to keep guessing until they correctly identify the number.

6. Display the number of attempts.

7. Implement input validation for non-numeric guesses.

8. Add a limited number of attempts to make the game more challenging.

**Example:**

```

Welcome to the Guess the Number Game!

Guess the number (1-100): 50

Too low. Try again.

Guess the number (1-100): 75

Too high. Try again.

Guess the number (1-100): 60

Congratulations! You guessed the number in 3 attempts.

```

### Homework 6: Multiplication Table

Create a Java program that generates and prints the multiplication table for a given number. Allow the
user to input the number for which they want to see the multiplication table. Use a for loop to iterate
through the multiplication table.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter a number for the multiplication table.


3. Use a for loop to generate and print the multiplication table for the entered number.

4. Include appropriate messages for clarity.

**Example:**

```

Welcome to the Multiplication Table Generator!

Enter a number: 7

Multiplication Table for 7:

7x1=7

7 x 2 = 14

7 x 3 = 21

...

7 x 10 = 70

```

### Homework 7: Palindrome Checker

Write a Java program that checks whether a given word is a palindrome or not. A palindrome is a word
that reads the same backward as forward. Implement a function that takes a word as input and returns
true if it is a palindrome, and false otherwise.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter a word.

3. Check whether the entered word is a palindrome.

4. Display a message indicating if the word is a palindrome or not.

5. Include appropriate messages for clarity.


**Example:**

```

Welcome to the Palindrome Checker!

Enter a word: radar

The word "radar" is a palindrome.

```

### Homework 8: Fibonacci Sequence

Write a Java program to generate the Fibonacci sequence up to a given number of terms. Allow the user
to input the number of terms they want to generate. Use a for loop to calculate and print the Fibonacci
sequence.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter the number of terms for the Fibonacci sequence.

3. Use a for loop to generate and print the Fibonacci sequence.

4. Include appropriate messages for clarity.

**Example:**

```

Welcome to the Fibonacci Sequence Generator!

Enter the number of terms: 8

Fibonacci Sequence:

0, 1, 1, 2, 3, 5, 8, 13

```

### Homework 9: Temperature Converter


Create a Java program that converts temperatures between Celsius and Fahrenheit. Prompt the user to
enter a temperature value and specify whether it is in Celsius or Fahrenheit. Use if-else statements to
perform the conversion and display the result.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter a temperature value.

3. Prompt the user to specify whether the temperature is in Celsius or Fahrenheit.

4. Perform the temperature conversion using if-else statements.

5. Display the converted temperature.

6. Include appropriate messages for clarity.

7. Handle unexpected inputs.

**Example:**

```

Welcome to the Temperature Converter!

Enter the temperature value: 32

Is the temperature in Celsius or Fahrenheit? (C/F): F

32.0 degrees Fahrenheit is equal to 0.0 degrees Celsius.

```

Certainly! Here are the original instructions along with example input and outputs for Homework 10, 11,
and 12:

### Homework 10: Sum of Digits


Write a Java program that calculates the sum of the digits of a given positive integer. Allow the user to
input the number, and use a loop to add up its individual digits.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter a positive integer.

3. Use a loop to calculate the sum of its digits.

4. Display the sum of digits.

5. Include appropriate messages for clarity.

**Example:**

```

Welcome to the Sum of Digits Calculator!

Enter a positive integer: 12345

The sum of the digits of 12345 is 15.

```

### Homework 11: Factorial Calculator

Implement a Java program that calculates the factorial of a given number. Allow the user to input the
number, and use a for loop to compute the factorial.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter a number for which they want to calculate the factorial.

3. Use a for loop to compute the factorial.

4. Display the calculated factorial.

5. Include appropriate messages for clarity.


**Example:**

```

Welcome to the Factorial Calculator!

Enter a number: 5

The factorial of 5 is 120.

```

### Homework 12: Pattern Printing

Create a Java program that prints a pattern using nested loops. For example, you can print a right-angled
triangle, a square, or any other pattern of your choice. Allow the user to input the size of the pattern.

**Instructions:**

1. Display a welcome message to the user.

2. Prompt the user to enter the size of the pattern.

3. Use nested loops to print the desired pattern.

4. Include appropriate messages for clarity.

**Example:**

```
Welcome to the Pattern Printing Program!

Enter the size of the pattern: 4

Pattern:

**

***

****

```

You might also like