
ask user how many numbers to be inputted and determine the sum and highest number using an array in java

import java.util.*;
class ArrayExample{
public static void main(String[] args) {
int largest = 0;
Scanner input = new Scanner(System.in);
System.out.print("How many numbers you want to display: ");
int n=input.nextInt();
System.out.println("Enter array values: ");
int arr[] = new int[n];
int sum=0;
for(int i = 0; i < arr.length; i++) {
arr[i] = input.nextInt();
if (largest < arr[i]) {
largest = arr[i];
}
sum+=arr[i];
}
System.out.println("Largest number is: " + largest);
System.out.println("Sum of array values: " + sum);
}
}

Thanks a lot for the code.... :) it helps me a lot.... :) ^_^
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.