# Check that if large number is divisible by 30

Here given code implementation process.

``````// Java program for
// Check that if large number is divisible by 30
public class Divisibility
{
public void isDivisibleBy30(String num)
{
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
boolean result = false;
int n = num.length();
if (n == 1 && num.charAt(0) == '0')
{
// When number is zero
result = true;
}
else if (n > 1)
{
// Check condition 1
if (num.charAt(n - 1) == '0')
{
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
int sum = 0;
// Calculate sum of all digit
for (int i = 0; i < n; ++i)
{
sum += (num.charAt(i) - 48);
}
if (sum % 3 == 0)
{
// When number is divisible by 3
result = true;
}
}
}
if (result == true)
{
System.out.println(" Given number (" +
num + ") is divisible by 30");
}
else
{
System.out.println(" Given number (" +
num + ") is not divisible by 30");
}
}
public static void main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30``````
``````// Include header file
#include <iostream>
#include <string>
using namespace std;
// C++ program for
// Check that if large number is divisible by 30
class Divisibility
{
public: void isDivisibleBy30(string num)
{
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
bool result = false;
int n = num.length();
if (n == 1 && num == '0')
{
// When number is zero
result = true;
}
else if (n > 1)
{
// Check condition 1
if (num[n - 1] == '0')
{
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
int sum = 0;
// Calculate sum of all digit
for (int i = 0; i < n; ++i)
{
sum += (num[i] - 48);
}
if (sum % 3 == 0)
{
// When number is divisible by 3
result = true;
}
}
}
if (result == true)
{
cout << " Given number ("
<< num << ") is divisible by 30" << endl;
}
else
{
cout << " Given number ("
<< num << ") is not divisible by 30" << endl;
}
}
};
int main()
{
// Test
return 0;
}``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30``````
``````// Include namespace system
using System;
// Csharp program for
// Check that if large number is divisible by 30
public class Divisibility
{
public void isDivisibleBy30(String num)
{
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
Boolean result = false;
int n = num.Length;
if (n == 1 && num == '0')
{
// When number is zero
result = true;
}
else if (n > 1)
{
// Check condition 1
if (num[n - 1] == '0')
{
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
int sum = 0;
// Calculate sum of all digit
for (int i = 0; i < n; ++i)
{
sum += (num[i] - 48);
}
if (sum % 3 == 0)
{
// When number is divisible by 3
result = true;
}
}
}
if (result == true)
{
Console.WriteLine(" Given number (" + num + ") is divisible by 30");
}
else
{
Console.WriteLine(" Given number (" + num + ") is not divisible by 30");
}
}
public static void Main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30``````
``````package main
import "fmt"
// Go program for
// Check that if large number is divisible by 30

func isDivisibleBy30(num string) {
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
var result bool = false
var n int = len(num)
if n == 1 && num == '0' {
// When number is zero
result = true
} else if n > 1 {
// Check condition 1
if num[n - 1] == '0' {
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
var sum int = 0
// Calculate sum of all digit
for i := 0 ; i < n ; i++ {
sum += (int(num[i]) - 48)
}
if sum % 3 == 0 {
// When number is divisible by 3
result = true
}
}
}
if result == true {
fmt.Println(" Given number (", num, ") is divisible by 30")
} else {
fmt.Println(" Given number (", num, ") is not divisible by 30")
}
}
func main() {

// Test
isDivisibleBy30("434534533434230")
isDivisibleBy30("43453453343432323423230")
isDivisibleBy30("895434230")
isDivisibleBy30("32340")
}``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30``````
``````<?php
// Php program for
// Check that if large number is divisible by 30
class Divisibility
{
public	function isDivisibleBy30(\$num)
{
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
\$result = false;
\$n = strlen(\$num);
if (\$n == 1 && \$num == '0')
{
// When number is zero
\$result = true;
}
else if (\$n > 1)
{
// Check condition 1
if (\$num[\$n - 1] == '0')
{
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
\$sum = 0;
// Calculate sum of all digit
for (\$i = 0; \$i < \$n; ++\$i)
{
\$sum += (ord(\$num[\$i]) - 48);
}
if (\$sum % 3 == 0)
{
// When number is divisible by 3
\$result = true;
}
}
}
if (\$result == true)
{
echo(" Given number (".\$num.
") is divisible by 30".
"\n");
}
else
{
echo(" Given number (".\$num.
") is not divisible by 30".
"\n");
}
}
}

function main()
{
// Test
}
main();``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30``````
``````// Node JS program for
// Check that if large number is divisible by 30
class Divisibility
{
isDivisibleBy30(num)
{
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
var result = false;
var n = num.length;
if (n == 1 && num.charAt(0) == '0')
{
// When number is zero
result = true;
}
else if (n > 1)
{
// Check condition 1
if (num.charAt(n - 1) == '0')
{
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
var sum = 0;
// Calculate sum of all digit
for (var i = 0; i < n; ++i)
{
sum += (num.charAt(i).charCodeAt(0) - 48);
}
if (sum % 3 == 0)
{
// When number is divisible by 3
result = true;
}
}
}
if (result == true)
{
console.log(" Given number (" + num + ") is divisible by 30");
}
else
{
console.log(" Given number (" + num + ") is not divisible by 30");
}
}
}

function main()
{
// Test
}
main();``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30``````
``````#  Python 3 program for
#  Check that if large number is divisible by 30
class Divisibility :
def isDivisibleBy30(self, num) :
#  A number is divisible by 30 when satisfies two conditions.
#  ➀ is divisible by 10.
#  ➁ is divisible by 3.
result = False
n = len(num)
if (n == 1 and num == '0') :
#  When number is zero
result = True
elif (n > 1) :
#  Check condition 1
if (num[n - 1] == '0') :
#  When number is divisible by 10
#  2nd condition check number is divisible by 3 or not
sum = 0
i = 0
#  Calculate sum of all digit
while (i < n) :
sum += (ord(num[i]) - 48)
i += 1

if (sum % 3 == 0) :
#  When number is divisible by 3
result = True

if (result == True) :
print(" Given number (", num ,") is divisible by 30")
else :
print(" Given number (", num ,") is not divisible by 30")

def main() :
#  Test

if __name__ == "__main__": main()``````

#### Output

`````` Given number ( 434534533434230 ) is not divisible by 30
Given number ( 43453453343432323423230 ) is divisible by 30
Given number ( 895434230 ) is not divisible by 30
Given number ( 32340 ) is divisible by 30``````
``````#  Ruby program for
#  Check that if large number is divisible by 30
class Divisibility
def isDivisibleBy30(num)
#  A number is divisible by 30 when satisfies two conditions.
#  ➀ is divisible by 10.
#  ➁ is divisible by 3.
result = false
n = num.length
if (n == 1 && num == '0')
#  When number is zero
result = true
elsif (n > 1)
#  Check condition 1
if (num[n - 1] == '0')
#  When number is divisible by 10
#  2nd condition check number is divisible by 3 or not
sum = 0
i = 0
#  Calculate sum of all digit
while (i < n)
sum += (num[i].ord - 48)
i += 1
end

if (sum % 3 == 0)
#  When number is divisible by 3
result = true
end

end

end

if (result == true)
print(" Given number (", num ,") is divisible by 30", "\n")
else

print(" Given number (", num ,") is not divisible by 30", "\n")
end

end

end

def main()
#  Test
end

main()``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30
``````
``````import scala.collection.mutable._;
// Scala program for
// Check that if large number is divisible by 30
class Divisibility()
{
def isDivisibleBy30(num: String): Unit = {
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
var result: Boolean = false;
var n: Int = num.length();
if (n == 1 && num.charAt(0) == '0')
{
// When number is zero
result = true;
}
else if (n > 1)
{
// Check condition 1
if (num.charAt(n - 1) == '0')
{
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
var sum: Int = 0;
var i: Int = 0;
// Calculate sum of all digit
while (i < n)
{
sum += (num.charAt(i).toInt - 48);
i += 1;
}
if (sum % 3 == 0)
{
// When number is divisible by 3
result = true;
}
}
}
if (result == true)
{
println(" Given number (" +
num + ") is divisible by 30");
}
else
{
println(" Given number (" +
num + ") is not divisible by 30");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Divisibility = new Divisibility();
// Test
}
}``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30``````
``````import Foundation;
// Swift 4 program for
// Check that if large number is divisible by 30
class Divisibility
{
func isDivisibleBy30(_ v: String)
{
let num = Array(v);
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
var result: Bool = false;
let n: Int = num.count;
if (n == 1 && num == "0")
{
// When number is zero
result = true;
}
else if (n > 1)
{
// Check condition 1
if (num[n - 1] == "0")
{
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
var sum: Int = 0;
var i: Int = 0;
// Calculate sum of all digit
while (i < n)
{
sum += (Int(UnicodeScalar(String(num[i]))!.value) - 48);
i += 1;
}
if (sum % 3 == 0)
{
// When number is divisible by 3
result = true;
}
}
}
if (result == true)
{
print(" Given number (", v ,") is divisible by 30");
}
else
{
print(" Given number (", v ,") is not divisible by 30");
}
}
}
func main()
{
// Test
}
main();``````

#### Output

`````` Given number ( 434534533434230 ) is not divisible by 30
Given number ( 43453453343432323423230 ) is divisible by 30
Given number ( 895434230 ) is not divisible by 30
Given number ( 32340 ) is divisible by 30``````
``````// Kotlin program for
// Check that if large number is divisible by 30
class Divisibility
{
fun isDivisibleBy30(num: String): Unit
{
// A number is divisible by 30 when satisfies two conditions.
// ➀ is divisible by 10.
// ➁ is divisible by 3.
var result: Boolean = false;
val n: Int = num.length;
if (n == 1 && num.get(0) == '0')
{
// When number is zero
result = true;
}
else if (n > 1)
{
// Check condition 1
if (num.get(n - 1) == '0')
{
// When number is divisible by 10
// 2nd condition check number is divisible by 3 or not
var sum: Int = 0;
var i: Int = 0;
// Calculate sum of all digit
while (i < n)
{
sum += (num.get(i).toInt() - 48);
i += 1;
}
if (sum % 3 == 0)
{
// When number is divisible by 3
result = true;
}
}
}
if (result == true)
{
println(" Given number (" +
num + ") is divisible by 30");
}
else
{
println(" Given number (" +
num + ") is not divisible by 30");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test
}``````

#### Output

`````` Given number (434534533434230) is not divisible by 30
Given number (43453453343432323423230) is divisible by 30
Given number (895434230) is not divisible by 30
Given number (32340) is divisible by 30``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.