Skip to content

Commit 3c92bc0

Browse files
committed
1
1 parent 189b6ef commit 3c92bc0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

for_loop/Project_program4.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Scanner;
2+
3+
public class Project_program4 {
4+
public static void main(String[] args) {
5+
Scanner x = new Scanner(System.in);
6+
System.out.println("Enter a number to check its a harshad's number or not");
7+
int num = x.nextInt();
8+
int rem = 0, sum = 0, n;
9+
10+
//Make a copy of num and store it in variable n
11+
n = num;
12+
13+
//Calculates sum of digits
14+
while(num > 0){
15+
rem = num%10;
16+
sum = sum + rem;
17+
num = num/10;
18+
}
19+
20+
//Checks whether number is divisible by sum of digits
21+
if(n%sum == 0)
22+
System.out.println(n + " is a harshad number");
23+
else
24+
System.out.println(n + " is not a harshad number");
25+
x.close();
26+
}
27+
}

0 commit comments

Comments
 (0)