Complete the Java ocode. The code should print how many times integer x appears in numbers. For example, if numbers = {2,2,1,3,2,2} and x = 2, your code should print the number 4, because x appears 4 times in the array
public static void main(String[] args){
int[] numbers = <some array values>;
int x = <some value>;
}
CODE IN JAVA:
public class Client {
public static void main(String[] args){
int[] numbers = {2, 2, 1, 3, 2, 2};
int x = 2;
int count = 0 ;
for(int val : numbers) {
if(val == x)
count += 1 ;
}
System.out.printf("%d appears %d times in the array.\n", x,
count);
}
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.