# Check that if large number is divisible by 16

Here given code implementation process.

``````// Java program for
// Check that if large number is divisible by 16
public class Divisibility
{
public void isDivisibleBy16(String num)
{
boolean result = false;
int length = num.length();
if (length == 1 && num.charAt(0) == '0')
{
result = true;
}
else if (length > 1)
{
int n = 0;
if (length == 2)
{
// Get 2 digit given number
n = (num.charAt(length - 2) - 48) * 10 +
(num.charAt(length - 1) - 48);
}
else if (length == 3)
{
// Get 3 digit number
n = ((num.charAt(length - 3) - 48) * 10 +
(num.charAt(length - 2) - 48)) * 10 +
(num.charAt(length - 1) - 48);
}
else
{
// Get last 4 digit number
n = (((num.charAt(length - 4) - 48) * 10 +
(num.charAt(length - 3) - 48)) * 10 +
(num.charAt(length - 2) - 48)) * 10 +
(num.charAt(length - 1) - 48);
}
if (n % 16 == 0)
{
result = true;
}
}
if (result)
{
System.out.println(" Given number (" +
num + ") is divisible by 16");
}
else
{
System.out.println(" Given number (" +
num + ") is not divisible by 16");
}
}
public static void main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16``````
``````// Include header file
#include <iostream>
#include <string>

using namespace std;
// C++ program for
// Check that if large number is divisible by 16
class Divisibility
{
public: void isDivisibleBy16(string num)
{
bool result = false;
int length = num.length();
if (length == 1 && num[0] == '0')
{
result = true;
}
else if (length > 1)
{
int n = 0;
if (length == 2)
{
// Get 2 digit given number
n = (num[length - 2] - 48) *10 + (num[length - 1] - 48);
}
else if (length == 3)
{
// Get 3 digit number
n = ((num[length - 3] - 48) * 10 +
(num[length - 2] - 48)) * 10 +
(num[length - 1] - 48);
}
else
{
// Get last 4 digit number
n = (((num[length - 4] - 48) * 10 +
(num[length - 3] - 48)) * 10 +
(num[length - 2] - 48)) * 10 +
(num[length - 1] - 48);
}
if (n % 16 == 0)
{
result = true;
}
}
if (result)
{
cout << " Given number ("
<< num << ") is divisible by 16" << endl;
}
else
{
cout << " Given number ("
<< num << ") is not divisible by 16" << endl;
}
}
};
int main()
{
// Test
return 0;
}``````

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16``````
``````// Include namespace system
using System;
// Csharp program for
// Check that if large number is divisible by 16
public class Divisibility
{
public void isDivisibleBy16(String num)
{
Boolean result = false;
int length = num.Length;
if (length == 1 && num[0] == '0')
{
result = true;
}
else if (length > 1)
{
int n = 0;
if (length == 2)
{
// Get 2 digit given number
n = (num[length - 2] - 48) * 10 +
(num[length - 1] - 48);
}
else if (length == 3)
{
// Get 3 digit number
n = ((num[length - 3] - 48) * 10 +
(num[length - 2] - 48)) * 10 +
(num[length - 1] - 48);
}
else
{
// Get last 4 digit number
n = (((num[length - 4] - 48) * 10 +
(num[length - 3] - 48)) * 10 +
(num[length - 2] - 48)) * 10 +
(num[length - 1] - 48);
}
if (n % 16 == 0)
{
result = true;
}
}
if (result)
{
Console.WriteLine(" Given number (" +
num + ") is divisible by 16");
}
else
{
Console.WriteLine(" Given number (" +
num + ") is not divisible by 16");
}
}
public static void Main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16``````
``````package main
import "fmt"
// Go program for
// Check that if large number is divisible by 16
type Divisibility struct {}
func getDivisibility() * Divisibility {
var me *Divisibility = &Divisibility {}
return me
}
func(this Divisibility) isDivisibleBy16(num string) {
var result bool = false
var length int = len(num)
if length == 1 && num[0] == '0' {
result = true
} else if length > 1 {
var n int = 0
if length == 2 {
// Get 2 digit given number
n = (int(num[length - 2]) - 48) * 10 +
(int(num[length - 1]) - 48)
} else if length == 3 {
// Get 3 digit number
n = ((int(num[length - 3]) - 48) * 10 +
(int(num[length - 2]) - 48)) * 10 +
(int(num[length - 1]) - 48)
} else {
// Get last 4 digit number
n = (((int(num[length - 4]) - 48) * 10 +
(int(num[length - 3]) - 48)) * 10 +
(int(num[length - 2]) - 48)) * 10 +
(int(num[length - 1]) - 48)
}
if n % 16 == 0 {
result = true
}
}
if result {
fmt.Println(" Given number (",
num, ") is divisible by 16")
} else {
fmt.Println(" Given number (",
num, ") is not divisible by 16")
}
}
func main() {
var task * Divisibility = getDivisibility()
// Test
}``````

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16``````
``````<?php
// Php program for
// Check that if large number is divisible by 16
class Divisibility
{
public	function isDivisibleBy16(\$num)
{
\$result = false;
\$length = strlen(\$num);
if (\$length == 1 && \$num[0] == '0')
{
\$result = true;
}
else if (\$length > 1)
{
\$n = 0;
if (\$length == 2)
{
// Get 2 digit given number
\$n = (ord(\$num[\$length - 2]) - 48) * 10 +
(ord(\$num[\$length - 1]) - 48);
}
else if (\$length == 3)
{
// Get 3 digit number
\$n = ((ord(\$num[\$length - 3]) - 48) * 10 +
(ord(\$num[\$length - 2]) - 48)) * 10 +
(ord(\$num[\$length - 1]) - 48);
}
else
{
// Get last 4 digit number
\$n = (((ord(\$num[\$length - 4]) - 48) * 10 +
(ord(\$num[\$length - 3]) - 48)) * 10 +
(ord(\$num[\$length - 2]) - 48)) * 10 +
(ord(\$num[\$length - 1]) - 48);
}
if (\$n % 16 == 0)
{
\$result = true;
}
}
if (\$result)
{
echo(" Given number (".\$num.
") is divisible by 16".
"\n");
}
else
{
echo(" Given number (".\$num.
") is not divisible by 16".
"\n");
}
}
}

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

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16``````
``````// Node JS program for
// Check that if large number is divisible by 16
class Divisibility
{
isDivisibleBy16(num)
{
var result = false;
var length = num.length;
if (length == 1 && num.charAt(0) == '0')
{
result = true;
}
else if (length > 1)
{
var n = 0;
if (length == 2)
{
// Get 2 digit given number
n = (num.charAt(length - 2).charCodeAt(0) - 48) * 10 +
(num.charAt(length - 1).charCodeAt(0) - 48);
}
else if (length == 3)
{
// Get 3 digit number
n = ((num.charAt(length - 3).charCodeAt(0) - 48) * 10 +
(num.charAt(length - 2).charCodeAt(0) - 48)) * 10 +
(num.charAt(length - 1).charCodeAt(0) - 48);
}
else
{
// Get last 4 digit number
n = (((num.charAt(length - 4).charCodeAt(0) - 48) * 10 +
(num.charAt(length - 3).charCodeAt(0) - 48)) * 10 +
(num.charAt(length - 2).charCodeAt(0) - 48)) * 10 +
(num.charAt(length - 1).charCodeAt(0) - 48);
}
if (n % 16 == 0)
{
result = true;
}
}
if (result)
{
console.log(" Given number (" + num + ") is divisible by 16");
}
else
{
console.log(" Given number (" + num + ") is not divisible by 16");
}
}
}

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

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16``````
``````#  Python 3 program for
#  Check that if large number is divisible by 16
class Divisibility :
def isDivisibleBy16(self, num) :
result = False
length = len(num)
if (length == 1 and num[0] == '0') :
result = True
elif (length > 1) :
n = 0
if (length == 2) :
#  Get 2 digit given number
n = (ord(num[length - 2]) - 48) * 10 + (
ord(num[length - 1]) - 48)
elif (length == 3) :
#  Get 3 digit number
n = ((ord(num[length - 3]) - 48) * 10 + (
ord(num[length - 2]) - 48)) * 10 + (
ord(num[length - 1]) - 48)
else :
#  Get last 4 digit number
n = (((ord(num[length - 4]) - 48) * 10 + (
ord(num[length - 3]) - 48)) * 10 + (
ord(num[length - 2]) - 48)) * 10 + (
ord(num[length - 1]) - 48)

if (n % 16 == 0) :
result = True

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

def main() :
#  Test

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

#### Output

`````` Given number ( 16 ) is divisible by 16
Given number ( 1242 ) is not divisible by 16
Given number ( 5645642343454564556756753444344367867872 ) is divisible by 16
Given number ( 4345345343456564564 ) is not divisible by 16
Given number ( 65756754674560 ) is divisible by 16``````
``````#  Ruby program for
#  Check that if large number is divisible by 16
class Divisibility
def isDivisibleBy16(num)
result = false
length = num.length
if (length == 1 && num[0] == '0')
result = true
elsif (length > 1)
n = 0
if (length == 2)
#  Get 2 digit given number
n = (num[length - 2].ord - 48) * 10 +
(num[length - 1].ord - 48)
elsif (length == 3)
#  Get 3 digit number
n = ((num[length - 3].ord - 48) * 10 +
(num[length - 2].ord - 48)) * 10 +
(num[length - 1].ord - 48)
else

#  Get last 4 digit number
n = (((num[length - 4].ord - 48) * 10 +
(num[length - 3].ord - 48)) * 10 +
(num[length - 2].ord - 48)) * 10 +
(num[length - 1].ord - 48)
end

if (n % 16 == 0)
result = true
end

end

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

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

end

end

def main()
#  Test
end

main()``````

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16
``````
``````import scala.collection.mutable._;
// Scala program for
// Check that if large number is divisible by 16
class Divisibility()
{
def isDivisibleBy16(num: String): Unit = {
var result: Boolean = false;
var length: Int = num.length();
if (length == 1 && num.charAt(0) == '0')
{
result = true;
}
else if (length > 1)
{
var n: Int = 0;
if (length == 2)
{
// Get 2 digit given number
n = (num.charAt(length - 2).toInt - 48) * 10 +
(num.charAt(length - 1).toInt - 48);
}
else if (length == 3)
{
// Get 3 digit number
n = ((num.charAt(length - 3).toInt - 48) * 10 +
(num.charAt(length - 2).toInt - 48)) * 10 + (
num.charAt(length - 1).toInt - 48);
}
else
{
// Get last 4 digit number
n = (((num.charAt(length - 4).toInt - 48) * 10 +
(num.charAt(length - 3).toInt - 48)) * 10 +
(num.charAt(length - 2).toInt - 48)) * 10 +
(num.charAt(length - 1).toInt - 48);
}
if (n % 16 == 0)
{
result = true;
}
}
if (result)
{
println(" Given number (" + num + ") is divisible by 16");
}
else
{
println(" Given number (" + num + ") is not divisible by 16");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Divisibility = new Divisibility();
// Test
}
}``````

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16``````
``````import Foundation;
// Swift 4 program for
// Check that if large number is divisible by 16
class Divisibility
{
func isDivisibleBy16(_ x: String)
{
let num = Array(x);
var result: Bool = false;
let length: Int = num.count;
if (length == 1 && num[0] == "0")
{
result = true;
}
else if (length > 1)
{
var n: Int = 0;
if (length == 2)
{
// Get 2 digit given number
n = (Int(UnicodeScalar(
String(num[length - 2]))!.value) - 48) * 10 +
(Int(UnicodeScalar(String(num[length - 1]))!.value) - 48);
}
else if (length == 3)
{
// Get 3 digit number
n = ((Int(UnicodeScalar(
String(num[length - 3]))!.value) - 48) * 10 +
(Int(UnicodeScalar(
String(num[length - 2]))!.value) - 48)) * 10 +
(Int(UnicodeScalar(
String(num[length - 1]))!.value) - 48);
}
else
{
// Get last 4 digit number
n = (((Int(UnicodeScalar(
String(num[length - 4]))!.value) - 48) * 10 +
(Int(UnicodeScalar(
String(num[length - 3]))!.value) - 48)) * 10 +
(Int(UnicodeScalar(
String(num[length - 2]))!.value) - 48)) * 10 +
(Int(UnicodeScalar(
String(num[length - 1]))!.value) - 48);
}
if (n % 16 == 0)
{
result = true;
}
}
if (result)
{
print(" Given number (", x ,") is divisible by 16");
}
else
{
print(" Given number (", x ,") is not divisible by 16");
}
}
}
func main()
{
// Test
}
main();``````

#### Output

`````` Given number ( 16 ) is divisible by 16
Given number ( 1242 ) is not divisible by 16
Given number ( 5645642343454564556756753444344367867872 ) is divisible by 16
Given number ( 4345345343456564564 ) is not divisible by 16
Given number ( 65756754674560 ) is divisible by 16``````
``````// Kotlin program for
// Check that if large number is divisible by 16
class Divisibility
{
fun isDivisibleBy16(num: String): Unit
{
var result: Boolean = false;
val length: Int = num.length;
if (length == 1 && num.get(0) == '0')
{
result = true;
}
else if (length > 1)
{
var n: Int ;
if (length == 2)
{
// Get 2 digit given number
n = (num.get(length - 2).toInt() - 48) * 10 +
(num.get(length - 1).toInt() - 48);
}
else if (length == 3)
{
// Get 3 digit number
n = ((num.get(length - 3).toInt() - 48) * 10 +
(num.get(length - 2).toInt() - 48)) * 10 +
(num.get(length - 1).toInt() - 48);
}
else
{
// Get last 4 digit number
n = (((num.get(length - 4).toInt() - 48) * 10 +
(num.get(length - 3).toInt() - 48)) * 10 +
(num.get(length - 2).toInt() - 48)) * 10 +
(num.get(length - 1).toInt() - 48);
}
if (n % 16 == 0)
{
result = true;
}
}
if (result)
{
println(" Given number (" + num + ") is divisible by 16");
}
else
{
println(" Given number (" + num + ") is not divisible by 16");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test
}``````

#### Output

`````` Given number (16) is divisible by 16
Given number (1242) is not divisible by 16
Given number (5645642343454564556756753444344367867872) is divisible by 16
Given number (4345345343456564564) is not divisible by 16
Given number (65756754674560) is divisible by 16``````

## 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.