# Xoriant off campus coding question and solution

Here we will discuss off campus coding question asked in Xoriant off campus recruitment. Xoriant coding question with solution.

## Xoriant Question

For the question below we define a internal number as any number whose last digit is 6, and a external number as any number that is less than 56.

You have to take the input from user until he enters negative number. Then

You have to change the program so that any number in the array is replaced by -3. if it’s a internal number, with -7 if it’s a external number, and with -9 if it is both, a internal and external number.

Example:

input:

96 68 12 46 -1

Output:

-3 68 -7 -9

Explanation:

Input is checked for divisible by 6 if it’s truereturn -3, if the input is less than 56 return -7. if it satisfy both conditions then return -9.

Algorithm to solve

1. To take the input from user untill user enters negative number, use a while loop
2. As we are not sure about how many elements we are going to enter so use ArrayList, whose size increases automatically.
3. Once your done with taking input from user just convery arraylist to array.
4. Write nested if else statements to check for given conditions and write output accordingly.
5. At the end modify array accordingly and print the array.

JAVA CODE

```package arrayproblems;
import java.util.*;
class problem7 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
ArrayList array1=new ArrayList();
System.out.println("enter the elements of array");

boolean flag = true;
while(flag) {
int a=sc.nextInt();
if(a>0) {
}
else {
flag=false;
}
}

System.out.println(array1);
int[] array2=new int[array1.size()];

for(int i=0;i<array1.size();i++) {
array2[i]=(int) array1.get(i);
}
for(int i=0;i<array2.length;i++) {

if(array2[i]%10==6 && array2[i]<56) {
array2[i]=-9;
}
else if(array2[i]%10==6){
array2[i]=-3;
}
else if(array2[i]<56) {
array2[i]=-7;
}
}
for(int i:array2) {
System.out.print(i+ " ");
}
}

}
```

Similar Questions

Complete Solution For Rob And Mars Problem In Java

Crack TCS Coding Round By solving These Questions

L&T off campus coding question solved