-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Special.java
48 lines (46 loc) · 1.04 KB
/
Special.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
38
39
40
41
42
43
44
45
46
47
48
/*
The program is to check whether a given number is a special number or not.
A special number is a number whose all digits are 1
Example-11,111
*/
import java.util.*;
class special
{
static void number(int x)
{
int s=0,c=0;
while(x!=0)
{
int b=x%10;
/*sum of digits*/
s=s+b;
/*count of digits*/
c++;
x=x/10;
}
/*If the sum of digits and count
of digits is equal
then special*/
if(s==c)
System.out.println("The given number is special");
else
System.out.println("The given number is not special");
}
public static void main()
{
Scanner sc=new Scanner(System.in);
/*Input number
which is to be checked*/
System.out.println("Enter the number");
int n=sc.nextInt();
number(n);
}
}
/*
Time Complexity:O(n)
Space Complexity:O(1)
Input/Output:-
Enter the number
1111
The given number is special
*/