Question: Problem 1 Difficulty: HARD Problem Statement: Create a class named Main with a main ( ) method to take positive integers as user input and
Problem
Difficulty: HARD
Problem Statement:
Create a class named Main with a main method to take positive integers as user
input and store in an integer array named nums.
Subsequently, create a class named Solution with a method named divide which
accepts nums as its parameter and returns an int value.
The functionality of the divide method is as follows: Each element within nums must
be allocated into either of two arrays, First or Second, ensuring that both First and
Second contain at least one element, and that the averages of elements within First
and Second are equal.
The method should return the average as integer floor value in case of floating point
if achieving such an allocation is possible, and otherwise.
Display the returned value from the divide method in the main method.
Please note that for an array, the average is determined by the summation of all its
elements divided by the length of the array.
Constraints:
nums.length
numsi
Code Structure
Use this syntax for writing your solution. You may define any other methods in
Solution class to make your code read
import java.util.Scanner;
class Main
public static void mainString args
Take input for integer array nums
Scanner scanner new ScannerSystemin;
int n scanner.nextInt; first integer is the size of the
array
int nums new intn;
for int i ; i n; i
numsi scanner.nextInt;
scanner.close;
Solution solution new Solution;
int result solution.dividenums;
System.out.printlnresult;
class Solution
public int divideint nums
Method implementation as described:
return ; Place
holder return value
NOTE
Only use array data structure as taught in labs and class for this problem.
You should only make use of Scanner package wherever necessary, no other
packages are allowed.
Input format
First line takes the length of the array. Second line contains the elements of the array
separated by space.
Output format
Single interger
Please solve this dont use plagarism. should with output also. please give full code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
