KnowledgeBoat Logo

Computer Applications

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 those numbers ending with 0 (zero).

Java

Java Iterative Stmts

96 Likes

Answer

import java.util.Scanner;

public class KboatDivisibleBy5
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n, c = 0;
        System.out.println("Enter 50 numbers");
        for (int i = 1; i <= 50; i++) {
            n = in.nextInt();
            if (n % 5 == 0) {
                if (n % 10 == 5)
                    System.out.println("Number end with the digit 5");
                if (n % 10 == 0)
                    c++;
            }
        }
        System.out.println("Count of numbers ending with 0: " + c);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of 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 those numbers ending with 0 (zero).BlueJ output of 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 those numbers ending with 0 (zero).

Answered By

31 Likes


Related Questions