Write a class ElementCheck with a public method checkFirstOrLast that takes two parameters one is arr of type int[] and second one is arg of type int and returns true

Write a class ElementCheck with a public method checkFirstOrLast that takes two parameters one is arr of type int[] and second one is arg of type int and returns true if the arg is first or last element in the arr else returns false. The return type of checkFirstOrLast is boolean.

Write a class ElementCheck with a public method checkFirstOrLast

Assumption:

  1. arr is never null

Here is an example:

Enter no of elements in the array: 4
Enter elements in the array seperated by space:1 2 3 6
Enter the search element:6
true

Note: Please don’t change the package name.

Solution:

package q11047;
public class ReversePrint { 
    
    /** * write a logic to find the array of elements in reverse order.
    * 
    *
    * 
    @return the reverseArray */
    
	public int[] reversePrint(int[] arr) { 
	    //Wrtie code here 
	    
	    int[] ReversePrint = new int[arr.length];
	    
	    for(int i = 0; i<arr.length; i++){ 
	        
	        ReversePrint[i] = arr[arr.length-1-i]; 
	    } 
	        return ReversePrint;
	        }
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *