write a java program to check if a number is divisible by both 5 and 7
Answers
Answered by
8
The given code is written in Java.
import java.util.*;
public class CheckDivisible{
public static void main(String s[]){
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int n=sc.nextInt();
if(n%5==0 && n%7==0)
System.out.println("Number is divisible by 5 and 7.");
else
System.out.println("Number is not divisible by 5 or 7 or both.");
sc.close();
}
}
The problem is solved using modulo operator. If the number leaves remainder 0 when divided by 5 and 7, then the number is divisible by both 5 and 7 else not.
See attachments for output.
Attachments:
Similar questions
Math,
3 hours ago
Science,
5 hours ago
Math,
5 hours ago
Accountancy,
7 months ago
Science,
7 months ago
Business Studies,
7 months ago