InterviewSolution
| 1. |
Write a Java Program that takes an integer and tests whether it is divisible by 2, 4 and 5. Apply divisibility rules that say: a. a number is divisible by 2 if the number is ending in an even digit 0,2,4,6,8.b. a number is divisible by 4 if last 2 digits of the number are divisible by 4.c. a number is divisible by 5 if the number is ending in 0 or 5 |
|
Answer» en problem is solved using language - Java.import java.util.Scanner; public CLASS Java{ public static void main(String s[]){ Scanner sc=new Scanner(System.in); System.out.print("Enter a number: "); int n=sc.nextInt(); System.out.println("Is the number DIVISIBLE by 2? - "+(n%2==0)); System.out.println("Is the number divisible by 4? - "+(n%4==0)); System.out.println("Is the number divisible by 5? - "+(n%5==0)); } }ACCEPT the number from the user.Check if divisible by 2, 5 and 10 using MODULO operator and DISPLAY the result.See the attachment for output. |
|