The document contains a Java class named 'Abc' that includes a method to find the maximum value in an integer array and return a specific result based on that maximum. The main method initializes an array, prints its elements, and calls the 'getNum' method to compute and display an integer that cannot be formed as the sum of two integers in the array. The result is calculated as twice the maximum value of the array plus one.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views1 page
class Abc
The document contains a Java class named 'Abc' that includes a method to find the maximum value in an integer array and return a specific result based on that maximum. The main method initializes an array, prints its elements, and calls the 'getNum' method to compute and display an integer that cannot be formed as the sum of two integers in the array. The result is calculated as twice the maximum value of the array plus one.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
class Abc {
static int getNum(int arrayA[], int a){
int max = arrayA[0]; for(int i = 0; i < a; i++){ //for loop to get the maximum value max = Math.max(max, arrayA[i]); } return 2*max + 1; // result will be 2 times maximum value + 1 } public static void main(String[] args) { //main method int arrayA[] = {2, 4, 7, 9, 8, 5, 6}; // initializing the array (testing with this array) int a = arrayA.length; // to find length of the array
System.out.print("The given ArrayA is : "); // to print the array
for(int i = 0; i < a; i++) // for loop to print the elements of an array System.out.print(arrayA[i] + " "); System.out.println("\n");//to print a line
int res = getNum(arrayA, a); // To get the result and store in res System.out.println("An integer that cannot be formed as the sum of two integers in arrayA: " + res); } }