Write a Java program to check and print whether a number is multiple of 13 or not
Answers
Answered by
3
Answer:
This is the required Java program for the question.
import java.util.*;
public class isMultiple {
public static void main(String args[]) {
System.out.print("Enter a number: ");
int a=(new Scanner(System.in)).nextInt();
if(a%13==0)
System.out.println("Number is multiple of 13.");
else
System.out.println("Number is not a multiple of 13.");
}
}
Explanation:
- A number is said to be a multiple of 13 if it leaves 0 as remainder when divided by 13. So, we have to check if the remainder obtained is 0 or not.
- To calculate remainder, the modulo operator is used. Here, the number is stored in variable 'a'. So, a%13 gives the remainder. To check for equality, the == operator is used. Therefore, the condition becomes - a%13==0. If the condition is true, number is a multiple of 13 else not.
Refer to the attachment.
•••♪
Attachments:
Answered by
2
Answer:
Program:-
import java.util.*;
public class Multiple
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int n;
System.out.println("Enter the number");
n=in.nextInt();
if(n%13==0)
{
System.out.println("It is a multiple of 13");
}
else
System.out.println("It is not a multiple of 13");
}
}
Similar questions