4. Write a program to enter any 50 numbers and check whether they are divisible
by 5 or not. If divisible then perform the following tasks:
(a) Display all the numbers ending with the digit 5.
(b) Count and display the numbers ending with 0 (zero).
Answers
Answered by
10
Answer:
import java.util.Scanner;
public class Check_Divisiblity
{
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
if(n % 5 == 0)
{
System.out.println(n+" is divisible by 5");
}
else
{
System.out.println(n+" is not divisible by 5");
}
}
}
Output:
$ javac Check_Divisiblity.java
$ java Check_Divisiblity
Enter any number:45
45 is divisible by 5
Enter any number:16
16 is not divisible by 5
Similar questions