Computer Science, asked by wolfyyyzzz, 29 days ago

write a java program to check if a number is divisible by both 5 and 7

Answers

Answered by anindyaadhikari13
8

\texttt{\textsf{\large{\underline{The C{o}de}:}}}

The given co‎de 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