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
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
g
ReplyDelete