Question: Create a Java program that contains a method that does the following; The name of your method shall be named isBalanced. This method will take
Create a Java program that contains a method that does the following; The name of your method shall be named isBalanced. This method will take a non-empty array of integers and return true if the array can be split in a way that the sum of numbers on the left side equals the sum of numbers in the right side, return false otherwise.
i.e.
isBalanced({2,2,3,3,4}) - true
isBalanced({2,1,3,3,4}) - false
isBalanced({3,1,1,1}) - true
Within your program create an additional method called intGroups that would take an integer as an argument and return the appropriate array. The array would be constructed as follows; given n>= 0, the array shall have the pattern {1, 1, 2, 1, 2, 3, ... 1, 2, 3 .. n} (spaces added to show the grouping). Take into account that the length of the array will be 1 + 2 + 3 ... + n, which is known to sum to exactly n*(n + 1)/2.
i.e.
intGroups(3) - {1,1,2,1,2,3}
intGroups(2) - {1,1,2}
Note: Can someone help me write the code for this practice program as simple as possible. It is for my intro to computer science class. Your assistance is greatly appreciated. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
