forked from spandey1296/Learn-Share-Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fascinating_number.java
37 lines (34 loc) ยท 1.16 KB
/
Fascinating_number.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
// When a number (3 digit or more) is multiplied by 2 and 3 and when both these products are concatenenated with the original number then
// it result in all digit from 1 to 9
public class Fascinating_number {
public static void main(String[] args) {
System.out.println("Enter a number");
Scanner scn = new Scanner(System.in);
int num = scn.nextInt();
int n2, n3;
n2 = num * 2;
n3 = num * 3;
String str = num + "" + n2 + n3;
boolean flag = true;
// System.out.println(str);
for (char c = '1'; c <= '9'; c++) {
int count = 0;
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch == c) {
count++;
}
}
if (count > 1 || count == 0) {
flag = false;
break;
}
}
if (flag) {
System.out.println(str + " is a Fascinating number");
} else {
System.out.println(str + " is not a Fascinating number");
}
}
}