WAP to check whether a number a number is divisible by 7 but not by 13 using scanner.

1 year ago
OOP Java

Compile code:

import java.util.Scanner;

 

public class Divisible_by7butnotby13{

    public static void main(String[]args)

    {

        int n,r1,r2;

        Scanner s=new Scanner(System.in);

 

        System.out.println("Enter any number:")

        n=s. nextInt();

        r1=n%7;

        r2=n%13;

        

        if(r1==0&&r2==0)

        System.out.println("is divisible by both 7and 13");

        else if(r1==0)

        System.out.println("is divisible by  7 only but not by 13");

        else if(r2==0)

        System.out.println("is divisible by 13 only but not by 7");

     }

}

 

Output:

0
Dipti KC
Jan 8, 2023
More related questions

Questions Bank

View all Questions