forked from AneriMehta/DivisibilityTestPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsDivisibleby9.java
More file actions
34 lines (30 loc) · 862 Bytes
/
IsDivisibleby9.java
File metadata and controls
34 lines (30 loc) · 862 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
29
30
31
32
// Java program to find if a number is
// divisible by 9 or not
package isdivisibleby9;
import java.util.*;
class IsDivisibleby9
{
// Function to find that number
// is divisble by 9 or not
static boolean check(String str)
{
// Compute sum of digits
int n = str.length();
int digitSum = 0;
for (int i=0; i<n; i++)
digitSum += (str.charAt(i)-'0');
// Check if sum of digits is divisible by 9.
return (digitSum % 9 == 0);
}
// main function
public static void main (String[] args)
{
System.out.println("Enter the number");
Scanner x = new Scanner(System.in);
String str = x.nextLine();
if(check(str))
System.out.println("Yes");
else
System.out.println("No");
}
}