Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the following piece of code to generate an array of integers. At the end of

ID: 3532298 • Letter: U

Question

Use the following piece of code to generate an array of integers. At the end of execution

of this code, the numbers variable is a sorted array containing 1000 random integers. The

location of the numbers.txt file should be the following: workspace/project/<here>. It

should exist in the same folder as src and bin.



int[] numbers = new int[1000];

try {

Scanner scanner = new Scanner(new File("numbers.txt"));

for (int i = 0; i < 1000; i++) {

numbers[i] = scanner.nextInt();

}

} catch (FileNotFoundException e) {

System.out.println("A problem occurred reading the file numbers.txt");

System.exit(0);

}



? Write a Java program that searches the array to check whether or not an integer exists in it.

? Your program should contain both Binary and Linear search.

? Your program should also calculate the time it takes for both of the Binary and Linear search

portion of your program.

You may use the long time = System.nanoTime(); statement in Java to store the current

system time in nanoseconds in any place of your program. You may take the total time it

takes for your searches by storing the current system time in before and after the search and

then taking the difference of those two system times.


? A sample input of your program could be the following:

Please enter Integer: 2998

Binary Search Result: Integer Found

Binary Search Took: 20013 nanoseconds

Linear Search Result: Integer Found

Linear Search Took: 10210 nanoseconds

Explanation / Answer

#include #include void main() { int a[5],i; int ele,temp=0,pos=0; clrscr(); printf("enter the array elements "); for (i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote