Capgemini ADAPT 2022 Solution | Largest Array Problem Solution in Java
Capgemini ADAPT 2022 Solution | Largest Array Problem Solution in Java

In this post, you will get the solution to the first problem of Capgemini ADAPT 2022 solution the problem Largest Array in Java.

Note: The solutions are provided for learning purposes only. 

Largest Array Problem Description:


Write a program which takes two arrays of the same size as input and compares the first element of the first array with the first element of the output array. Repeat the process till the last element of the first array is checked with the last element of the second array.

Include a function named largestArray that accepts 3 arguments and its return type is void. The first argument is input array 1, the second argument is input array 2, and the third argument is an int that corresponds to the size of the array. The output array is stored in a global variable named output1.

If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.

Input & Output Format of Largest Array:


Input consists of n+1 integers. The first integer corresponds to n number of elements in the array. The next ‘n’ Integers correspond to the elements in the array.

Largest Array Problem Solution in Java:


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
 int n, i, j, flag = 0;
Scanner in = new Scanner(System.in);
n = in .nextInt();
 n = in .nextInt();
if (n < 0) {
System.out.print("Invalid Input");
System.exit(0);
} else {
int a[] = new int[n];
for (i = 0; i < n; i++) {
a[i] = in .nextInt();
if (a[i] < 0) {
System.out.print("Invalid Input");
System.exit(0);
}
}
 int b[] = new int[n];
for (i = 0; i < n; i++) {
b[i] = in .nextInt();
if (b[i] < 0) {
System.out.print("Invalid Input");
System.exit(0);
}
}
 int output1[] = new int[100];
for (i = 0; i < n; i++) {
if (a[i] > b[i]) {
output1[i] = a[i];
} else {
output1[i] = b[i];
}
}
for (i = 0; i < n; i++) {
System.out.println(output1[i]);
}
}
}
}

 

TOP COMPANIES HIRING DRIVE

BATCHWISE OFF-CAMPUS DRIVES

1. TCS OFF-CAMPUS DRIVES1. 2018 BATCH
2. INFOSYS OFF-CAMPUS DRIVES2. 2019 BATCH
3. COGNIZANT OFF-CAMPUS DRIVES3. 2020 BATCH
4. WIPRO OFF-CAMPUS DRIVES4. 2021 BATCH
5. CAPGEMINI OFF-CAMPUS DRIVES5. 2022 BATCH

 

To Stay Up-to-date, Follow us on Social Media:


1.      Join our Telegram Channel:

Click Here

2.      Like us on Facebook:

Click Here

3.      Follow us on Instagram:

Click Here

4.      Follow us on LinkedIn:

Click Here

5.      Follow us on Google News:

Click Here

 

Capgemini ADAPT Sprint 1 (Bus Reservation Solutions):


Capgemini ADAPT Sprint 2 (Bus Reservation System):


Study Materials for Interview Preparation (FREE MATERIALS):


  1. 240 Core Java Questions & Answers with PDF Download Link – Click Here
  2. 230+ SQL interview questions & answers pdf download – Click Here
  3. 50 LeetCode Interview Questions with Answers – PDF Notes – Click Here