0% found this document useful (0 votes)
94 views2 pages

Assignment Questions - Java Arrays PDF

The document discusses Java arrays and includes questions about working with arrays. It provides examples of printing positive values from an array, converting a list to an array and accessing elements, using a for-each loop to print even elements, finding the minimum element using a method, and locating the first peak element between neighbors.

Uploaded by

Ashish
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)
94 views2 pages

Assignment Questions - Java Arrays PDF

The document discusses Java arrays and includes questions about working with arrays. It provides examples of printing positive values from an array, converting a list to an array and accessing elements, using a for-each loop to print even elements, finding the minimum element using a method, and locating the first peak element between neighbors.

Uploaded by

Ashish
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
You are on page 1/ 2

Java Arrays

Assignment Questions
Assignment Questions

Q1. Given an array of integers {2, 6, -5, -1, 0, 4, -9}, print only the positive values present in the array. (Easy)
Output:
2
6
0
4

Q2. Convert the list of Strings {“ab”, “bc”, “cd”, “de”, “ef”, “fg”, “gh”} into an array of strings and print all (Easy)
strings stored on odd indices of the array.

Output:
bc
de
fg

Q3. Traverse over the elements of the array {1,2,3,4,5,6,7,8} using for each loop and print all even (Easy)
elements.

Output:
2
4
6
8

Q4. Calculate the minimum element in the array {2, -3, 5, 8, 1, 0, -4} using standard library method (Easy)
for calculating the minimum element.

Output:
-4
(Medium)
Q5. Find the first peak element in the array {1, 1, 3, 4, 2, 3, 5, 7, 0}
Peak element is the one which is greater than its immediate left neighbor and its immediate right neighbor.
Leftmost and rightmost element cannot be a peak element.

Output:
7

Cracking the Coding Interview in Java - Foundation

You might also like