Answer to Question #255060 in Java | JSP | JSF for kayjay

Question #255060

a)   Draw a flowchart, lastLargestIndex, that takes as parameters an int array and its size and returns the index of the last occurrence of the largest element in the array.


1
Expert's answer
2021-10-22T04:53:42-0400

Source code



public class Main
{
    static int getlastLargestIndex(int [] arr, int n){
        int max = arr[0];
        int lastLargestIndex=0;
        for(int i=0;i<n;i++){
            if(arr[i]>=max){
                max=arr[i];
                lastLargestIndex=i;
            }
            
        }
        return lastLargestIndex;
    }
	public static void main(String[] args) {
		int [] arr={10,11,12,24,21,24,12,24,23,21};
		int n=10;
		System.out.println("The elements of the array are: ");
		for(int i=0;i<n;i++){
		    System.out.print(arr[i]+" ");
		}
		System.out.println("\nThe index of the last occurrence of the largest element in the array: "+getlastLargestIndex(arr,n));
	}
}


Output





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS