forked from ishanjogalekar/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27.weird_num.java
More file actions
28 lines (28 loc) · 752 Bytes
/
27.weird_num.java
File metadata and controls
28 lines (28 loc) · 752 Bytes
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
import java.util.Scanner;
public class weird_num {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int count =0;
System.out.println("Enter N:");
int N = in.nextInt();
System.out.println("Enter K:");
int K = in.nextInt();
for(int i=1;i<=N;i++){
if((i % K !=0 )&&(find_sum(i)% K == 0)){
count++;
}
}
System.out.println("Total weird numbers are: "+count);
}
//Method to find sum of digits
static int find_sum(int N){
int digit, sum = 0;
while(N > 0)
{
digit = N % 10;
sum = sum + digit;
N = N / 10;
}
return sum;
}
}