This is a simple Java program I made that takes in any number, and when it gets to 0, it returns the quantity of the numbers, the min, max, sum, and average of the numbers. Are there any ways how I can make the code more readable or improve the performance?
import java.util.Scanner; public class Stats { public static void main(String[] args){ Scanner scan = new Scanner(System.in); int size = 0; double max = 0; double min = 0; double sum = 0; double avg = 0; String num = null; do { num = scan.nextLine(); try { double n = Double.parseDouble(num); if(!num.equals("0")){ if(size == 0){ max = n; min = n; sum = n; avg = n; } else { max = Math.max(n, max); min = Math.min(n, min); sum += n; avg = ((avg*size)+n)/(size+1); } size++; } } catch(NumberFormatException ex){ System.out.println("Please input a number, try again."); } } while(!num.equals("0")); System.out.println("size: " + size + "\nmin: " + min + "\nmax: " + max + "\nsum: " + sum + "\navg: " + avg); } }