DUET PG Score Card 2021
NHAI Recruitment 2021
Bihar Board 12th Dummy Admit Card 2022
RBI Assistant Notification 2021
Jee Advanced 2021 Result
NIACL Assistant Recruitment 2021
SBI PO Online Form 2021

Write a class ElementCount with a main method which passes an arr of type int[] and an element of type int. Print number of

write a class ElementCount with a main method which passes an arr of type int[] and an element of type int. Print number of times the element is present in the arr.

Here is an example:

int[] arr = {1, 12, 9, 3, 5, 3, 78, 4, 3, 9, 18, 56, 1, 5}
Cmd Args : 1
2

Note: Please don’t change the package name.

Solution:

package q11049;
public class ElementCount {
	public static void main(String[] args) {
	    
		int[] arr = { 1, 12, 9, 3, 5, 3, 78, 4, 3, 9, 18, 56, 1, 5 };
		int element = Integer.parseInt(args[0]);
		int count = 0;
		
		for (int i = 0; i<arr.length; i++) {
		    
			if (arr[i] == element) {
				count++;
			}
		}
		
		System.out.println(count);
	}
}

Candidates having any kind of query so he/she can ask in our comment section. Our Panel will b reverting back as soon as possible. Thank You. For more details visit our website (https://speedjobalert.com/)

Leave a Comment