Java > 🧑💻 Exercise 2
Arrays
Problem 1: Even Numbers Array
Description: Write a Java program to initialize an array variable with first 10 even numbers and output the first element, middle elements and last element
Example:
Input: myArr = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}
Output:
First: 2
Middle: 10, 12
Last: 20
Problem 2: Vowels Array
Description: Write a Java program to initialize an array variable containing all vowels and output same
Example:
Input: vowels = {a, e, i, o, u}
Output: Vowels: a, e, i, o, u
Problem 3: Sum of Array Elements
Description: Write a Java program to declare array variable with integer type and print the sum of all elements.
Example:
Input: Declare array of numbers and provide values {1, 2, 3, 4, 5}
Output: Sum = 15
Problem 4: Average of Array Elements
Description: Write a Java program to declare array variable with integer type and print the average of all elements.
Example:
Input: Declare array of numbers and provide values {10, 20, 30, 40, 50}
Output: Average = 30.0
Problem 5: Swap First and Last Elements in an Array
Description: Write a Java program to swap the first and last elements of an array.
Example:
Input: Declare array of numbers and provide values {5, 10, 15, 20, 25}
Output: Modified Array = {25, 10, 15, 20, 5}
Problem 6: Access and Print Specific Elements
Description: Write a Java program to swap the first and last elements of an array.
Example:
Input: Declare char array {'J', 'a', 'v', 'a'}
Output: First: J Last: a
Problem 7: Length of a Char Array
Description: Write a Java program to find the length of characters array
Example:
Input: Declare letters = {'H', 'e', 'l', 'l', 'o'}
Output: Length: 5
| ← Excercise 1 | Excercise 3 → |
🔗 Related Topics: