How to Find the Index of Largest Number in Array in Java

This is the simple but logic building program in java for beginners. The 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.

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


Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment