You are here:   HomeJava ProgrammingJava ArrayLargest Number in an Array Java Example
by Dinesh Thakur Category: array

Algorithm for Largest Number in an Array:

 

step 1: set big=0,small=0

step 2: read arr_size

step 3: create an integer array a[] of size arr_size

step 4: initialize x=0

step 5: repeat through step-7 while x less than a.length

step 6: read a[x]

step 7: x= x+ 1

step 8: Initialize x=0

step 9: repeat through step-12 while x less than a.length

step 10: print a[x]

step 11: print one space

step 12: x=x+1

step 13: initialize x=0

step 14: repeat through step-16 while x less than a.length

step 15: if a[x] greater than big then big=a[x]

step 16: x=x+1

step 17: print big

step 18: Exit

Here is the Java Example for Largest Number in an Array:

import java.util.Scanner;

public class LargestNumberinArray
{
              public static void main(String args[])
      {
              int x,y,big=0,small=0;
              Scanner sl=new Scanner(System.in);
              System.out.print("Enter The Size of Array : ");
              y=sl.nextInt();
              int a[]=new int[y];
              System.out.println("Enter The Elements");
              for(x=0;x<a.length;x++)
              a[x]=sl.nextInt();
              System.out.println("\n Print The Elements of Array \n" );
              for(x=0;x<a.length;x++)
              System.out.print(a[x]+" ");
              for(x=0;x<a.length;x++)
                 {
                   if(a[x]>big)
                    {
                      big=a[x];
                    }
                 }
System.out.println("Largest Number in an Array is : "+big);
      }
}

Largest Number in an Array





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article