Question
can you complete java code for main method, just for what i write in bold Write a java program (xxxxxp1.java where xxxxx is the first
can you complete java code for main method, just for what i write in bold
Write a java program (xxxxxp1.java where xxxxx is the first five characters of your last name and p1 is the project number) that contains the following methods:
- A method that returns 2nd largest in an array with n elements.
- A method that prints (formatted) array elements 10 elements per line.
- A mergesort method that mergesorts array elements in descending order.
- A binary search method that searches x in a sorted array with n elements and returns its position if exist, -1 otherwise.
public static void main(String args[]) throws exception{
try{
Scanner inf = new Scanner (System.in);
n = inf.nextInt(); // read no. of input
xxxxxp1 p1 = new xxxxxp1 (n);
read n integers and store them in array arr and print arr(formatted) 10 elements per line. (40 pts)
find 2nd largest and print it. (40 pts)
mergesort array arr and print arr(formatted) 10 elements per line. (80 pts)
k = inf.nextInt(); // read no. of elements to search
read k keys to search using binary search and print their position in array arr. (40 pts)
}catch (Exception e) {prt(" Exception " + e + " ");}
}// end main method
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started