Answer:
Here is code in java.
//import package
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
try{
// declare and initialize array
int[] arr1 = {1,5,10,2,4,-3,6};
int num1=3;
System.out.println("Numbers greater than "+num1+" in the 1st array are :");
// call the function to print the Number greater than 3
fun(arr1,num1);
// declare and initialize array
int[] arr2 = {10, 12, 15, 24};
int num2 = 12;
System.out.println("Numbers greater than "+num2+" in the 2nd array are :");
// call the function to print the Number greater than 12
fun(arr2, num2);
}catch(Exception ex){
return;}
}
public static void fun(int[] arr,int n)
{
for(int i=0; i<arr.length; i++)
{
// if the array element is greater than the value of n, then print it
if (arr[i]>n)
System.out.print(arr[i]+" ");
}
System.out.println();
}
}
Step-by-step explanation:
Declare and initialize an array "arr1" and a variable "num1" with 3. then call the function "fun()" with parameter "arr1" and a Number "num1",if the element of the array is greater that the value of "n" then it will print that element of the array. Similarly call the function "fun()" with parameter "arr2" and number "num2".
Output:
Numbers greater than 3 in the 1st array are :
5 10 4 6
Numbers greater than 12 in the 2nd array are :
15 24