# How To Check Whether a Number Is a Insolite Number or Not in Java?

A number is said to be an Insolite number, if the number is divisible by both addition of squares of each digit and square of the whole product value of all digits.

For more clarification, we have to find the addition of squares of each digit. Then we have to multiply each digit of the given number and after that we have to calculate the square value of it. If the given number is divisible by both the resultant values, then we can say that the given number is an Insolite number.

In this article we will see how to check if a number is Insolite by using Java programming language.

## To show you some instances

### Instance-1

Input number is 1122112.

Let’s check it by using the logic of the Insolite number.

The addition of squares of each digit of 1122112 is =

= (1^2) + (1^2) ++ (2^2) + (2^2) + (1^2) + (1^2) + (2^2)
= 1 + 1 + 4 + 4 + 1 + 1 + 4 = 16


The square of the whole production value of all digits of 1122112 =

=(1 * 1 * 2 * 2 * 1 * 1 * 2 ) ^ 2 = 64


1122112 is divisible by both 16 and 64.

Hence, 1122112 is an Insolite number.

### Instance-2

Input number is 123123.

Let’s check it by using the logic of the Insolite number.

The addition of squares of each digit of 123123 is =

=(1^2) + (2^2) ++ (3^2) + (1^2) + (2^2) + (3^2)
= 1 + 4 + 9 + 1 + 4 + 9 = 28


The square of the whole production value of all digits of 123123=

=(1 * 2 * 3 * 1 * 2 * 3) ^ 2 = 1296


123123 is not divisible by both 28 and 1296.

Hence, 123123 is not an Insolite number.

### Instance-3

Input number is 121212.

Let’s check it by using the logic of the Insolite number.

The addition of squares of each digit of 121212 is =

= (1^2) + (2^2) ++ (1^2) + (2^2) + (1^2) + (2^2)
= 1 + 4 + 1 + 4 + 1 + 4 = 15


The square of the whole production value of all digits of 121212 =

= (1 * 2 * 1 * 2 * 1 * 2) ^ 2 = 64


121212 is not divisible by both 15 and 64.

Hence, 123123 is not an Insolite number.

## Syntax

To get the power of any number raised to the power of another number in Java we have inbuilt java.lang.Math.pow() method.

Following is the syntax to get power of 2 by using the method

double power = Math.pow(inputValue,2)


## Algorithm

• Step 1 − Get an integer number either by initialization or by user input.

• Step 2 − Then take a loop till the binary number is equal to zero.

• Step 3 − Calculate the sum and product of the square of each digit.

• Step 4 − Finally, check the condition whether the resultant values are divisible by our input number or not.

• Step 5 − If it is divisible then we conclude that the number is an insolite number otherwise the number is not an insolite number.

## Multiple Approaches

We have provided the solution in different approaches.

• By Using Static Input Value

• By Using User Defined Method

Let’s see the program along with its output one by one.

### Approach-1: By Using Static Input Value

In this approach one integer value will be initialized in the program and then by using the algorithm we can check whether a number is an insolite number or not.

#### Example

import java.util.*;
import java.lang.Math;
public class Main{
//main method
public static void main (String[] args){

//declare a variable with a static input value
int inputNumber = 1122112 ;

//store the input number into an another variable
int temp = inputNumber;

// for storing the addition value declare a variable
int sum = 0;

// for storing the multiplication value declare a variable
int prod = 1;

//loop to calculate both sum and product value
while (temp != 0){

// take digits from unit place
int i = temp % 10;

//calculate the sum value
sum = sum + (int)Math.pow(i, 2);

//calculate the multiplication value
prod = prod * (int)Math.pow(i, 2);

//removing that unit place value
temp = temp / 10;
}
//check the condition
//whether both resultant values are divisible by inputNumberor not
if((inputNumber % sum == 0) && (inputNumber % prod == 0))
System.out.print(inputNumber + " is an Insolite Number.");
else
System.out.print(inputNumber + " is not an Insolite Number.");
}
}


#### Output

1122112 is an Insolite Number.


### Approach-2: By Using User Defined

In this approach the user will be asked to take the input of an integer value and then we will call a user defined method by passing this input number as parameter.

Inside the method we will check whether a number is an insolite number or not by using the algorithm.

#### Example

public class Main{
//main method
public static void main (String[] args){
//declare an int variable and initialize a number
int inputNumber =126317;
System.out.println("Given number: "+inputNumber);

//call the user defined method inside conditional statement
if (checkInsolite(inputNumber)){
//if its true
System.out.println(inputNumber + " is an Insolite Number.");
} else {
//if its true
System.out.println(inputNumber + " is not an Insolite Number.");
}
}
// define the user defined method
// check for Insolitenumber
static boolean checkInsolite(int inputNumber){
//store the input number into an another variable
int temp = inputNumber;
// for storing the addition value declare a variable
int sum = 0;
// for storing the multiplication value declare a variable
int prod = 1;
//loop to calculate both sum and product value
while (temp != 0){

// take digits from unit place
int i = temp % 10;
//calculate the sum value
sum = sum + i * i;
//calculate the multiplication value
prod = prod * i * i;
//removing that unit place value
temp = temp / 10;
}
//check the condition
//whether both resultant values are divisible by inputNumberor not
if((inputNumber % sum == 0) && (inputNumber % prod == 0))
return true;
else
return false;
}
}


#### Output

Given number: 126317
126317 is not an Insolite Number.


In this article, we explored how to check a number whether it is an insolite number or not in Java by using different approaches.