Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Use JAVA to write a program to read 10 integers from the keyboard and store them in the integer array a
Use JAVA to write a program to read 10 integers from the keyboard and store them in the integer array a

package javaTest;

import java.io.BufferedReader;

import java.io.IOException;

import java.io. InputStreamReader;

public class Read {

public static void main(String[] args) {

BufferedReader br=new BufferedReader(new InputStreamReader(System.in ));

int []a=new int[10];

int max=a[0],sum=0,flag=0;

for(int i=0;i

{

try {

System.out.print("Please enter the "+(i+1)+" number: ");

a[i]=Integer.parseInt(br.readLine());

} catch (IOException e ) {

e.printStackTrace();

}

}

for(int i=0;i

{

sum+=a[i];

if(a[i]>max)

{< /p>

max=a[i];

flag=i;

}

}

System.out .println("The maximum value is: "+max+" and its position is;"+(flag+1));

System.out.println("The sum of 10 elements is: "+sum) ;

}

}