013-003-007
Standard Library: Array Operations (Arrays)
Medium
Problem Description
Standard Library: array Operations (Arrays)
In this problem, you will create a program that reads an integer array and a search target from standard input, sorts the array using Arrays.sort(), searches for an element using Arrays.binarySearch(), and displays the results to standard output.
Learning Objective: Learn to sort and search arrays efficiently using Java's Arrays class
Overview
Use static methods of the Arrays class to sort an integer array and search for elements. Use Arrays.sort() and Arrays.binarySearch().
Input Format
N
a1 a2 ... aN
target
- Line 1: array size N
- Line 2: N space-separated integers
- Line 3: search target value
Output Format
Sorted: [sorted array]
Index of {target}: {index}
Sample Input
5
5 2 8 1 9
8
Sample Output
Sorted: [1, 2, 5, 8, 9]
Index of 8: 3
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up