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.



96 68 12 46 -1


-3 68 -7 -9


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.


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 {
		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) {
			else if(array2[i]%10==6){
			else if(array2[i]<56) {
		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

4 thoughts on “Xoriant off campus coding question and solution”

  1. Pingback: Taking N number of inputs from user - Is It Actually

  2. Pingback: Rotate Array Elements towards Right Side - Is It Actually

  3. Pingback: Maximum Work Hacker Earth Problem solved - Is It Actually

  4. Pingback: SHL off campus coding Questions - Is It Actually

Leave a Comment

Your email address will not be published. Required fields are marked *