Wednesday, May 23, 2012

need to create array which prints maximum+location after taking 5 inputs

import java.util.Scanner;

public class Arraymaxloc {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int[] a = new int[5];
int c = 1;
while (c < a.length) {
c = s.nextInt();
}
int max = a[0];
int loc = -1;
while (c < a.length) {
if (a[c] > max == true) {
max = a[c];
loc = c;
c++;
} else {
c++;
}
System.out.println("max found at" + loc);
}
}
}




No comments:

Post a Comment