sujonshekh

Max Array Position

Jun 16th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package array;
  6.  
  7. import java.util.Scanner;
  8.  
  9. /**
  10.  *
  11.  * @author cse
  12.  */
  13. public class Array {
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) {
  19.         int a[]= new int[5];
  20.         Scanner sc= new Scanner(System.in);
  21.        
  22.        
  23.        for (int i=0;i<=4;i++)
  24.          a[i]=sc.nextInt();
  25.          
  26.          int pos=0;
  27.          int max= a[0];
  28.          for (int i=1;i<=4;++i){
  29.              if (max<a[i])
  30.                  max= a[i];
  31.              pos= i;
  32.          }
  33.          System.out.println("Max: "+max);
  34.          System.out.println(pos);
  35.     }
  36. }
Add Comment
Please, Sign In to add comment