Showing posts with label How to Find the Index of largest Number in Array in Java. Show all posts
Showing posts with label How to Find the Index of largest Number in Array in Java. Show all posts

Monday, 23 February 2015

Find the Index of largest Number in Array in Java

Structure of the Problem Requirements 

This Program will return the index of the largest number in Array in Java Program. There is a simple logic for this and here is the complete code of this program. To get the same program code in C++ click here.

Source Code

import java.util.Scanner;
public class Arrayindex {


public static void main(String[] args) {
System.out.println("\t\t\t LEP Tutorials");
Scanner input = new Scanner (System.in);
int [] num = new int [5];
int a=0, index =0;
for (int i =0;i<5;i++)
{
System.out.print("Enter Your Number :");
num[i] = input.nextInt();
}
for (int i =0;i<5;i++)
{
if (num[i] >a)
{
a =num [i];
index = i;
}
}
System.out.println("The largest Number is the Array is :" + index);
}
}

Output of the Program

Find the Index of largest Number in Array in Java