Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Are there any errors or suggestions to improve this code : // import import java.util.Scanner; import java.util.Arrays; public class GenXandY { // Define constant array

Are there any errors or suggestions to improve this code :

// import import java.util.Scanner; import java.util.Arrays;

public class GenXandY { // Define constant array size static final int ARRAYSIZE = 100;

public static void main(String[] args){ int x = 0; int[] intValues = new int[ARRAYSIZE]; int y = 0; for (int i=0; i

if (args.length == 2) { // Command line input x = Integer.parseInt(args[0]); // Stores numbers on command line x and y y = Integer.parseInt(args[1]); System.out.println("Search for x and y values: " + args[0] + ", " + args[1]); }else { // Exit program with instructions System.out.println("Enter 2 sets of double number, e.g., 30 50 "); System.exit(0); }

// Sort the int array value Arrays.sort(intValues);

// Print the sorted array for (int i=0; i

int arrIndex = Arrays.binarySearch(intValues,lookFor); System.out.println("The index with value " + x + " is : " + arrIndex); System.out.println("The index with value " + y + " is : " + arrIndex);

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions