# Check that if large number is divisible by 8

Here given code implementation process.

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

#### Output

`````` Given number (45645645) is not divisible by 8
Given number (65765345345) is not divisible by 8
Given number (5654464564564564512320) is divisible by 8
Given number (56456423434545645567567567867824) is divisible by 8
Given number (9999) is not divisible by 8``````
``````// Include header file
#include <iostream>
#include <string>
using namespace std;
// C++ program for
// Check that if large number is divisible by 8
class Divisibility
{
public: void isDivisibleBy8(string num)
{
bool result = false;
int n = num.length();
int auxiliary = 0;
if (n == 1 && (num == '0' || num == '8'))
{
result = true;
}
else if (n == 2)
{
auxiliary = num[n - 2] *10 + num[n - 1];
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num[n - 3] - 48) *10 +
(num[n - 2] - 48)) *10 + (num[n - 1] - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
if (result)
{
cout << " Given number ("
<< num << ") is divisible by 8" << endl;
}
else
{
cout << " Given number ("
<< num << ") is not divisible by 8" << endl;
}
}
};
int main()
{
// Test
return 0;
}``````

#### Output

`````` Given number (45645645) is not divisible by 8
Given number (65765345345) is not divisible by 8
Given number (5654464564564564512320) is divisible by 8
Given number (56456423434545645567567567867824) is divisible by 8
Given number (9999) is not divisible by 8``````
``````// Include namespace system
using System;
// Csharp program for
// Check that if large number is divisible by 8
public class Divisibility
{
public void isDivisibleBy8(String num)
{
Boolean result = false;
int n = num.Length;
int auxiliary = 0;
if (n == 1 && (num == '0' ||
num == '8'))
{
result = true;
}
else if (n == 2)
{
auxiliary = num[n - 2] * 10 + num[n - 1];
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num[n - 3] - 48) * 10 +
(num[n - 2] - 48)) * 10 + (num[n - 1] - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
if (result)
{
Console.WriteLine(" Given number (" +
num + ") is divisible by 8");
}
else
{
Console.WriteLine(" Given number (" +
num + ") is not divisible by 8");
}
}
public static void Main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number (45645645) is not divisible by 8
Given number (65765345345) is not divisible by 8
Given number (5654464564564564512320) is divisible by 8
Given number (56456423434545645567567567867824) is divisible by 8
Given number (9999) is not divisible by 8``````
``````package main
import "fmt"
// Go program for
// Check that if large number is divisible by 8

func isDivisibleBy8(num string) {
var result bool = false
var n int = len(num)
var auxiliary int = 0
if n == 1 && (num == '0' || num == '8') {
result = true
} else if n == 2 {
auxiliary = int(num[n - 2]) * 10 +int( num[n - 1])
if auxiliary % 8 == 0 {
result = true
}
} else if n > 2 {
// Get last three digit number
auxiliary = ((int(num[n - 3]) - 48) * 10 +
(int(num[n - 2]) - 48)) * 10 + (int(num[n - 1]) - 48)
if auxiliary % 8 == 0 {
result = true
}
}
if result {
fmt.Println(" Given number (", num, ") is divisible by 8")
} else {
fmt.Println(" Given number (", num, ") is not divisible by 8")
}
}
func main() {

// Test
isDivisibleBy8("45645645")
isDivisibleBy8("65765345345")
isDivisibleBy8("5654464564564564512320")
isDivisibleBy8("56456423434545645567567567867824")
isDivisibleBy8("9999")
}``````

#### Output

`````` Given number (45645645) is not divisible by 8
Given number (65765345345) is not divisible by 8
Given number (5654464564564564512320) is divisible by 8
Given number (56456423434545645567567567867824) is divisible by 8
Given number (9999) is not divisible by 8``````
``````<?php
// Php program for
// Check that if large number is divisible by 8
class Divisibility
{
public	function isDivisibleBy8(\$num)
{
\$result = false;
\$n = strlen(\$num);
\$auxiliary = 0;
if (\$n == 1 && (\$num == '0' ||
\$num == '8'))
{
\$result = true;
}
else if (\$n == 2)
{
\$auxiliary = ord(\$num[\$n - 2]) * 10 +
ord(\$num[\$n - 1]);
if (\$auxiliary % 8 == 0)
{
\$result = true;
}
}
else if (\$n > 2)
{
// Get last three digit number
\$auxiliary = ((ord(\$num[\$n - 3]) - 48) * 10 +
(ord(\$num[\$n - 2]) - 48)) * 10 +
(ord(\$num[\$n - 1]) - 48);
if (\$auxiliary % 8 == 0)
{
\$result = true;
}
}
if (\$result)
{
echo(" Given number (".\$num.
") is divisible by 8\n");
}
else
{
echo(" Given number (".\$num.
") is not divisible by 8\n");
}
}
}

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

#### Output

`````` Given number (45645645) is not divisible by 8
Given number (65765345345) is not divisible by 8
Given number (5654464564564564512320) is divisible by 8
Given number (56456423434545645567567567867824) is divisible by 8
Given number (9999) is not divisible by 8``````
``````// Node JS program for
// Check that if large number is divisible by 8
class Divisibility
{
isDivisibleBy8(num)
{
var result = false;
var n = num.length;
var auxiliary = 0;
if (n == 1 && (num.charAt(0) == '0' ||
num.charAt(0) == '8'))
{
result = true;
}
else if (n == 2)
{
auxiliary = num.charCodeAt(n - 2) * 10 +
num.charCodeAt(n - 1);
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num.charCodeAt(n - 3) * 10 +
(num.charCodeAt(n - 2) - 48)) * 10 +
(num.charCodeAt(n - 1) - 48));
if (auxiliary % 8 == 0)
{
result = true;
}
}
if (result)
{
console.log(" Given number (" + num + ") is divisible by 8");
}
else
{
console.log(" Given number (" + num + ") is not divisible by 8");
}
}
}

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

#### Output

`````` Given number (45645645) is not divisible by 8
Given number (65765345345) is not divisible by 8
Given number (5654464564564564512320) is divisible by 8
Given number (56456423434545645567567567867824) is divisible by 8
Given number (9999) is not divisible by 8``````
``````#  Python 3 program for
#  Check that if large number is divisible by 8
class Divisibility :
def isDivisibleBy8(self, num) :
result = False
n = len(num)
auxiliary = 0
if (n == 1 and(num == '0'
or num == '8')) :
result = True
elif (n == 2) :
auxiliary = ord(num[n - 2]) * 10 + ord(num[n - 1])
if (auxiliary % 8 == 0) :
result = True

elif (n > 2) :
#  Get last three digit number
auxiliary = ((ord(num[n - 3]) - 48) * 10 +
(ord(num[n - 2]) - 48)) * 10 + (ord(num[n - 1]) - 48)
if (auxiliary % 8 == 0) :
result = True

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

def main() :
#  Test

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

#### Output

`````` Given number ( 45645645 ) is not divisible by 8
Given number ( 65765345345 ) is not divisible by 8
Given number ( 5654464564564564512320 ) is divisible by 8
Given number ( 56456423434545645567567567867824 ) is divisible by 8
Given number ( 9999 ) is not divisible by 8``````
``````#  Ruby program for
#  Check that if large number is divisible by 8
class Divisibility
def isDivisibleBy8(num)
result = false
n = num.length
auxiliary = 0
if (n == 1 && (num == '0' || num == '8'))
result = true
elsif (n == 2)
auxiliary = num[n - 2].ord * 10 + num[n - 1].ord
if (auxiliary % 8 == 0)
result = true
end

elsif (n > 2)
#  Get last three digit number
auxiliary = ((num[n - 3].ord - 48) * 10 +
(num[n - 2].ord - 48)) * 10 +
(num[n - 1].ord - 48)
if (auxiliary % 8 == 0)
result = true
end

end

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

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

end

end

def main()
#  Test
end

main()``````

#### Output

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

#### Output

`````` Given number (45645645) is not divisible by 8
Given number (65765345345) is not divisible by 8
Given number (5654464564564564512320) is divisible by 8
Given number (56456423434545645567567567867824) is divisible by 8
Given number (9999) is not divisible by 8``````
``````import Foundation;
// Swift 4 program for
// Check that if large number is divisible by 8
class Divisibility
{
func isDivisibleBy8(_ t: String)
{
let num = Array(t);
var result: Bool = false;
let n: Int = num.count;
var auxiliary: Int = 0;
if (n == 1 && (num == "0" || num == "8"))
{
result = true;
}
else if (n == 2)
{
auxiliary = Int(UnicodeScalar(String(num[n - 2]))!.value) * 10 +
Int(UnicodeScalar(String(num[n - 1]))!.value);
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((Int(UnicodeScalar(String(num[n - 3]))!.value) - 48) *
10 + (Int(UnicodeScalar(String(num[n - 2]))!.value) -
48)) * 10 + (Int(UnicodeScalar(String(
num[n - 1]))!.value) - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
if (result)
{
print(" Given number (", t ,") is divisible by 8");
}
else
{
print(" Given number (", t ,") is not divisible by 8");
}
}
}
func main()
{
// Test
}
main();``````

#### Output

`````` Given number ( 45645645 ) is not divisible by 8
Given number ( 65765345345 ) is not divisible by 8
Given number ( 5654464564564564512320 ) is divisible by 8
Given number ( 56456423434545645567567567867824 ) is divisible by 8
Given number ( 9999 ) is not divisible by 8``````
``````// Kotlin program for
// Check that if large number is divisible by 8
class Divisibility
{
fun isDivisibleBy8(num: String): Unit
{
var result: Boolean = false;
val n: Int = num.length;
var auxiliary: Int ;
if (n == 1 && (num.get(0) == '0' ||
num.get(0) == '8'))
{
result = true;
}
else if (n == 2)
{
auxiliary = num.get(n - 2).toInt() * 10 +
num.get(n - 1).toInt();
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num.get(n - 3).toInt() - 48) * 10 +
(num.get(n - 2).toInt() - 48)) * 10 +
(num.get(n - 1).toInt() - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
if (result)
{
println(" Given number (" + num + ") is divisible by 8");
}
else
{
println(" Given number (" + num + ") is not divisible by 8");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test
}``````

#### Output

`````` Given number (45645645) is not divisible by 8
Given number (65765345345) is not divisible by 8
Given number (5654464564564564512320) is divisible by 8
Given number (56456423434545645567567567867824) is divisible by 8
Given number (9999) is not divisible by 8``````

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.

### New Comment 