diff --git a/java/IsDivisibleby2.java b/java/IsDivisibleby2.java new file mode 100644 index 0000000..2d90b62 --- /dev/null +++ b/java/IsDivisibleby2.java @@ -0,0 +1,14 @@ +import java.util.*; +class Main { + public static void main(String arg[]) { + Scanner in = new Scanner(System.in); + System.out.println("Enter Number"); + String n = in.nextLine(); + int l = n.length(); + if (n.charAt(l - 1) == '2' || n.charAt(l - 1) == '4' || n.charAt(l - 1) == '6' || n.charAt(l - 1) == '8' || n.charAt(l - 1) == '0') + System.out.println("Number is divisible by 2"); + else + System.out.println("Not Divisible by 2"); + } +} + diff --git a/python/divisibility_by_2.py b/python/divisibility_by_2.py new file mode 100644 index 0000000..5cb3a46 --- /dev/null +++ b/python/divisibility_by_2.py @@ -0,0 +1,15 @@ +print("Please Enter a number:") +n = int(input()) + +s = bin(n) + +if s[-1]=="1": + print("The Number is not divisible by 2") +else: + print("The Number is divisible by 2") + + + + + +