[Go to site: main page, start]

0% found this document useful (0 votes)
0 views9 pages

Java Array Basic Question

The document contains a series of programming tasks related to arrays in Java, including operations such as storing elements, calculating sums, finding averages, sorting, and identifying unique values. Each task is accompanied by sample outputs to illustrate the expected results. The tasks cover basic array manipulation techniques and provide a comprehensive overview of array handling in Java.

Uploaded by

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

Java Array Basic Question

The document contains a series of programming tasks related to arrays in Java, including operations such as storing elements, calculating sums, finding averages, sorting, and identifying unique values. Each task is accompanied by sample outputs to illustrate the expected results. The tasks cover basic array manipulation techniques and provide a comprehensive overview of array handling in Java.

Uploaded by

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

Q:-1

Write a program to store elements in an array and print it to


take the input from the user.
Sample Output
Array Size = 5
Element of a[0] = 5
Element of a[1] = 11
Element of a[2] = 22
Element of a[3] = 33
Element of a[4] = 44

Display Array Elements


5
11
22
33
44

Q:-2

Write a Java program code to count the number of elements


strictly greater than an element X in a given array {79, 70,
67, 30, 23, 20, 5, 3, 3, 2}.

Input:- X=20

Output:- Count=5

Q:-3

Write a program to print the sum values of an array

Sample Output

Array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Sum Values of Array = 55

Q:-4

Write a program to calculate the average value of array


elements

Sample Output

1|Page
JAVA ARRAY BASIC PROGRAM
Array = {1, 2, 3, 4, 5}

Sum of Array Value : 15

Average of Array Value : 3.0

Q:-5

Write a program in to find the sum of all elements of the


array

Sample Output

Array = {10, 20, 30, 40, 50, 60}

Sum of Array Elements = 210

Q:-6

Write a program to array elements to print cubic values

Sample Output

Array = {1, 2, 3, 4, 5}

Cubic Array Elements =1 8 27 64 125

Q:-7

Write a program to array elements and print all Odd number

Sample Output

Array = {23, 45, 67, 34, 78}

Odd Array Elements = 23 45 67

Q:-8

Write a program to array elements and print all Even number

Sample Output

Array = {23, 45, 89, 34, 12}

2|Page
JAVA ARRAY BASIC PROGRAM
Even Array Elements = 34 12
Q:-9

Write a program to array elements to print sum of Odd Numbers

Sample Output

Array = {12, 34, 59, 45, 22}

Sum of Odd Array Elements = 104

Q:-10

Write a program to array elements to print sum of Even Numbers

Sample Output

Array = {56, 78, 45, 79, 34}

Sum of Even Array Elements = 168

Q:-11

Write a program to array elements to print sum of Cubic Values

Sample Output

Array = {1, 2, 3, 4, 5}

Sum of Cubic Array Elements = 225

Q:-12

Write a program in to copy the elements of one array into


another array

Sample Output

Array = {1, 2, 3, 4, 5}

Copy Array Elements one to Another Array = {1, 2, 3, 4, 5}

Q:-13

3|Page
JAVA ARRAY BASIC PROGRAM
Write a program to merge two array elements to store a third
array

Sample Output

First Array = {1, 2, 3, 4, 5}

First Array = {6, 7, 8, 9, 10}

Merge two Array Elements = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Q:-14

Write a program to array elements and print all Positive


number

Sample Output

Array = {67, -4, 3, -5, 44}

Positive Array Elements = {67, 3, 44}

Q:-15

Write a program to array elements print all Negative number

Sample Output

Array = {-45, 32, -7, 3, -6}

Negative Array Elements = {-45, -7, -6}

Q:-16

Write a program to Sort an array in ascending order using


bubble sort

Sample Output

Array = {2, 65, 23, 13, 18, 30, 46, 17, 52, 78}

Sorted Array in Ascending Order = 2 13 17 18 23 30 46 52 65 78

4|Page
JAVA ARRAY BASIC PROGRAM
Q:-17

Write a program to Sort an array in descending order using


bubble sort

Sample Output

Array = {2, 65, 23, 13, 18, 30, 46, 17, 52, 78}

Sorted Array in Descending Order = 78 65 52 46 30 23 18 17 13


2

Q:-18

Write a program to search an element in an array

Sample Output

Array = {10, 20, 30, 40, 50}

Search Array Elements = 30

Element is Found in the Position = 3

Element is Found in the Index = 2

Q:-19

Write a program to Delete Duplicate Elements from an Array

Sample Output

Array = {10, 10, 20, 20, 30}

After Remove Duplicate Array Elements = {10, 20, 30 }

Q:-20

Write a program to find the largest element from an unsorted


array

5|Page
JAVA ARRAY BASIC PROGRAM
Sample Output

Array = {50, 20, 50, 40, 10}

Largest Element = 50

Q:-21

Write a program to find the smallest element from an unsorted


array

Sample Output

Array = {50, 20, 50, 40, 10}

Smallest Element = 10

Q:-22

Write a program to find the second-largest element from a


sorted array.

Sample Output

Array = {10, 20, 30, 40, 40}

Second Largest Element = 30

Q:-23

Write a program to find the second smallest element from a


sorted array

Sample Output

Array = {2,2,5,5,10,11,18,30}

Second Smallest Element = 5

Q:-24

Write a program to find the second-largest element from an


unsorted array

6|Page
JAVA ARRAY BASIC PROGRAM
Sample Output

Array = {2,12,9,5,10,11,1,30}

Second Largest Element = 12

Q:-25

Write a program to find the second smallest element from an


unsorted array

Sample Output

Array = {2,21,22,5,10,11,9,14}

Second Smallest Element = 5

Q:-26

Write a program to find the common elements between two arrays


of integers

Sample Output

First Array = {10, 20, 30, 40, 50}

Second Array = {10, 30, 60, 50, 70}

Common Array Elements = {10, 30, 50}

Q:-27

Write a program to find a missing number in an array

Sample Output

Array = {1, 2, 4, 5, 6, 7}

Missing Array Number = 3

Q:-28

7|Page
JAVA ARRAY BASIC PROGRAM
Write a program to Find prime and non-prime numbers in the
array

Sample Output

Array = {3, 12, 21, 11}

3 - Prime
12 - Not Prime
21 - Not Prime
11 - Prime

Q:-29

Write a program to Move all zero at the end of the array

Sample Output

Array = {1,0,45,34,0,67,2,0,6,67,45,2,0,10}

Array after Moving Zeros to End = 1 45 34 67 2 6 67 45 2 10 0


0 0 0

Q:-30

Write a program to read and print a two-dimensional array


using normal looping.

Sample Output

Rows = 2
Columns = 3

Enter Array Elements a[0][0] = 1


Enter Array Elements a[0][1] = 2
Enter Array Elements a[0][2] = 3
Enter Array Elements a[1][0] = 4
Enter Array Elements a[1][1] = 5
Enter Array Elements a[1][2] = 6

Display 2D Array Element


1 2 3
4 5 6

Q:-31

8|Page
JAVA ARRAY BASIC PROGRAM
Write a program to read and print a two-dimensional array
using for-each loop.

Sample Output

Rows = 2
Columns = 3

Enter Array Elements a[0][0] = 1


Enter Array Elements a[0][1] = 2
Enter Array Elements a[0][2] = 3
Enter Array Elements a[1][0] = 4
Enter Array Elements a[1][1] = 5
Enter Array Elements a[1][2] = 6

Display 2D Array Element


1 2 3
4 5 6

9|Page
JAVA ARRAY BASIC PROGRAM

You might also like