public class SearchNumber { int numarr[] = new int[10]; public void DisplayArray(int[] numarr) { for (int i = 0; i < numarr.length; i++) { System.out.println(numarr[i]); } } public void Search(int[] numarr) { int count = 0; // for (int i = 0; i < numarr.length; i++) { // if (numarr[i] == 100) { // count++; // System.out.println(+numarr[i] + " Found At Position Of the Index Number: " + (i + 1) + "."); // } // // } // System.out.println("--------------------------------------------------------"); // System.out.println("Count : " + count + " time that number is present in Array."); int index = 0; // Tracks the current index for (int num : numarr) { if (num == 100) { count++; System.out.println(num + " Found At Position Of the Index Number: " + (index + 1) + "."); } index++; // Increment the index for the next iteration } // Optionally print the total occurrences found System.out.println("Total occurrences of 100: " + count); } public int[] getNumarr() { return numarr; } public void setNumarr(int[] numarr) { this.numarr = numarr; } }