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,
14 days ago
English,
14 days ago
Physics,
14 days ago
Science,
29 days ago
Math,
29 days ago
Accountancy,
8 months ago
Science,
8 months ago
Business Studies,
8 months ago