Java
Fascinating Number Java Program The base condition to check whether a number is fascinating or not is that the number must have at least 3 or more than three digits. #Source_code #75
Steps to Find Fascinating Numbers
First, check the given number consist of three digits or not. If no, print cannot be a fascinating number.
Else, multiply the given number by 2 and 3, separately.
Convert the results (from step 2) into a string.
Concatenate the strings (from step 3) with the given number (n).
Iterate over the string that we get after concatenation and count the frequency of each digit.
Print "not a fascinating number" if any digit is missing or appeared multiple times. Else, print "fascinating number".
Let's implement the above steps in a Java program
#Output
#75
First, check the given number consist of three digits or not. If no, print cannot be a fascinating number.
Else, multiply the given number by 2 and 3, separately.
Convert the results (from step 2) into a string.
Concatenate the strings (from step 3) with the given number (n).
Iterate over the string that we get after concatenation and count the frequency of each digit.
Print "not a fascinating number" if any digit is missing or appeared multiple times. Else, print "fascinating number".
Let's implement the above steps in a Java program
#Output
#75
Java
#Source_code #76
Spy Number
A positive integer is called a spy number if the sum and product of its digits are equal. In other words, a number whose sum and product of all digits are equal is called a spy number.
#Output
#76
A positive integer is called a spy number if the sum and product of its digits are equal. In other words, a number whose sum and product of all digits are equal is called a spy number.
#Output
#76
Java
Sunny Number A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square. Let's understand it through an example. #Source_code #72
Steps to Find Sunny Number
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
Let's implement the above steps in a Java program.
#Output
#72
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
Let's implement the above steps in a Java program.
#Output
#72
Java
code.png
#Data_structure
#Output
#84
Example inputs for a given Data Structure:
Input:
string: codesleepcode
pattern: XYX
Output:
X: code
Y: sleep
Input:
string: codecodecode
pattern: XXX
Output:
X: code
#Output
#84
Example inputs for a given Data Structure:
Input:
string: codesleepcode
pattern: XYX
Output:
X: code
Y: sleep
Input:
string: codecodecode
pattern: XXX
Output:
X: code