0% found this document useful (0 votes)
8 views3 pages

Java Array Practice 20 Problems Only - md-1

The document contains a list of 20 practice problems for Java programming focused on 1D arrays. Each problem requires students to perform various operations such as storing, printing, summing, and analyzing arrays. The problems are designed to enhance the understanding of array manipulation without providing hints or answers.

Uploaded by

amrish84
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Java Array Practice 20 Problems Only - md-1

The document contains a list of 20 practice problems for Java programming focused on 1D arrays. Each problem requires students to perform various operations such as storing, printing, summing, and analyzing arrays. The problems are designed to enhance the understanding of array manipulation without providing hints or answers.

Uploaded by

amrish84
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

File: /home/amrish/Downloads/java_a…y_practice_20_problems_only.

md Page 1 of 3

# Java 1D Array – 20 Practice Problems (Questions Only)

Give this sheet to the student first, **without** hints or answers.

---

### 1. Store and print 5 ages


Create an `int` array of size 5 to store ages.
Assign any 5 ages of your choice and print all ages in one line.

---

### 2. Input and print 5 numbers


Write a program that:
- Takes 5 integers from the user (using `Scanner`) and stores them in an array.
- Prints all the numbers in the same order.

---

### 3. Print array with indexes


Write a program that:
- Takes 5 integers from the user into an array.
- Prints each element in the format:
`Index 0: <value>`
`Index 1: <value>`
and so on for all indexes.

---

### 4. Sum of array elements


Write a program that:
- Takes 5 integers from the user into an array.
- Calculates and prints the **sum** of all the elements.

---

### 5. Average of array elements


Write a program that:
- Takes 5 integers from the user into an array.
- Calculates and prints the **sum** and the **average** of the numbers.

---

### 6. Maximum value in an array


Write a program that:
- Reads 7 integers from the user into an array.
- Finds and prints the **largest** number in the array.

---

### 7. Minimum value in an array


Write a program that:
- Reads 7 integers from the user into an array.
- Finds and prints the **smallest** number in the array.

---

### 8. Count even and odd numbers


Write a program that:
File: /home/amrish/Downloads/java_a…y_practice_20_problems_only.md Page 2 of 3

- Reads 10 integers from the user into an array.


- Counts how many numbers are **even** and how many are **odd**.
- Prints both counts.

---

### 9. Print array in reverse order


Write a program that:
- Reads 5 integers from the user into an array.
- Prints the array elements in **reverse order** (from last index to first index).

---

### 10. Search for a number in an array


Write a program that:
- Reads 8 integers from the user into an array.
- Asks the user to enter a number `x`.
- Prints `"Found"` if `x` exists in the array, otherwise prints `"Not Found"`.

---

### 11. Count how many times a number appears


Write a program that:
- Reads 10 integers from the user into an array.
- Asks the user to enter a number `x`.
- Prints how many times `x` appears in the array.

---

### 12. Copy one array into another


Write a program that:
- Reads 5 integers from the user into an array `a`.
- Creates another array `b` of the same size.
- Copies all elements from `a` to `b`.
- Prints the new array `b`.

---

### 13. Element-wise sum of two arrays


Write a program that:
- Creates two arrays `a` and `b` of size 5.
- Reads 5 integers each for `a` and `b` from the user.
- Creates a third array `c` where `c[i] = a[i] + b[i]`.
- Prints the array `c`.

---

### 14. Swap first and last element


Write a program that:
- Reads 5 integers from the user into an array.
- Swaps the **first** and **last** elements of the array.
- Prints the array after swapping.

---

### 15. Check if array is sorted in increasing order


Write a program that:
- Reads 6 integers from the user into an array.
- Checks if the array is sorted in **non-decreasing** (increasing) order,
i.e., each element is less than or equal to the next one.
File: /home/amrish/Downloads/java_a…y_practice_20_problems_only.md Page 3 of 3

- Prints `"Sorted"` if it is sorted, otherwise prints `"Not Sorted"`.

---

### 16. Find index of the smallest element


Write a program that:
- Reads 7 integers from the user into an array.
- Finds the **smallest** number and prints:
- The smallest value
- The index at which it occurs

---

### 17. Find second largest element


Write a program that:
- Reads 7 **different** integers from the user into an array.
- Finds and prints the **second largest** number in the array.

---

### 18. Shift elements to the right by 1


Write a program that:
- Reads 5 integers from the user into an array.
- Creates a new array where every element is shifted to the **right by 1** position.
- The last element of the original array becomes the **first** element of the new array.
- Example: input `[1, 2, 3, 4, 5]` → output `[5, 1, 2, 3, 4]`.
- Prints the new array.

---

### 19. Count positive, negative and zero values


Write a program that:
- Reads 10 integers from the user into an array.
- Counts how many numbers are:
- positive
- negative
- zero
- Prints all three counts.

---

### 20. Total marks and highest mark


Write a program that:
- Reads marks in 5 subjects into an array `marks`.
- Calculates and prints:
- Total marks
- Average marks
- Highest mark

You might also like