From 710205ca2affbd0792eb800a8922ad15dbefdf5e Mon Sep 17 00:00:00 2001 From: JECKLY-01 <24s01acs017@anu.ac.ke> Date: Thu, 17 Oct 2024 00:39:43 +0300 Subject: [PATCH] Create countZeros.java --- Jeckly-01/countZeros.java | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Jeckly-01/countZeros.java diff --git a/Jeckly-01/countZeros.java b/Jeckly-01/countZeros.java new file mode 100644 index 00000000..67311f15 --- /dev/null +++ b/Jeckly-01/countZeros.java @@ -0,0 +1,45 @@ +import java.util.Scanner; + +public class + +countZeros { + int myArray[]; + + public static void main(String [] args) { + countZeros jeckly = new countZeros(); + jeckly.myArray = new int[5]; + + + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter " + jeckly.myArray.length + " numbers:"); + + for (int i = 0; i < jeckly.myArray.length; i++) { + System.out.println("Enter number " + (i + 1) + ":"); + jeckly.myArray[i] = scanner.nextInt(); + } + System.out.println("You entered:"); + for (int figures : jeckly.myArray) { + System.out.print(figures); + + } + int jecklyCount = jeckly.countZeros(); + System.out.println (); + System.out.println("The number of zeros is " + jecklyCount); + + scanner.close(); + + } + public int countZeros(){ + int counter = 0; + for (int figures : myArray) { + if (figures == 0) { + counter++; + } + + } +return counter; + } + + +}