Dremendo Tag Line

Input number check multiple of 7 or not using switch case in Java

switch case - Question 3

In this question, we will see how to input an integer and check whether it is a multiple of 7 or not in Java programming using the switch case statement. To know more about switch case statement click on the switch case statement lesson.

Q3) Write a program in Java to input an integer and check whether it is a multiple of 7 or not using the switch case statement.

Program

import java.util.Scanner;

public class Q3
{
    public static void main(String args[])
    {
        int n;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a number ");
        n=sc.nextInt();
        switch(n%7)
        {
            case 0:
                System.out.print("Multiple of 7");
                break;

            default:
                System.out.print("Not multiple of 7");
        }
    }
}

Output

Enter a number 49
Multiple of 7
video-poster