📘 Module 5: Arrays & Strings in Java
📝 Java Practice Assignment – Module 5
📚 Topic: Arrays & Strings 🎯 Level: Beginner to Intermediate 📦 Total Questions: 10 (with hints/examples)
🔶 Part A: Arrays (1D & 2D)
1. Write a program to store 5 integers in an array and print them using a for loop.
Hint: Use int[] arr = new int[5];
2. Write a program to calculate the sum and average of values stored in an integer array.
int[] marks = {90, 80, 70, 85, 95};
3. Write a program to find the maximum and minimum value from an array.
4. Write a program to count the number of even and odd numbers in an integer array.
5. Write a program to traverse and print a 2D array (matrix of 3x3 elements).
int[][] mat = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
🔷 Part B: Strings
6. Write a program to count the number of vowels in a given string.
Input: "Java Programming"
Output: 5
7. Write a program to reverse a string using a for loop or StringBuilder.
8. Write a program to check if two strings are equal (case-insensitive).
9. Write a program to convert a string to uppercase and lowercase, and print both.
10. Write a program to replace all spaces in a string with a dash (-).
Example:
Input: "Java is fun"
Output: "Java-is-fun"
🔸 Bonus Challenge:
🔁 Write a program that takes a sentence from the user and:
- Splits it into words using
split()
- Prints total word count
- Prints each word on a new line
📌 Submission Format:
- Code must be properly indented and commented
- Each question should be in a separate
.java
file - Optional: Add user input (
Scanner
) where applicable
Comments