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); } }
0 comments:
Post a Comment