Question: I need a little help with my java coding. I need to check that the user actually entered 5 to 10 NUMBERS and no letters.
I need a little help with my java coding. I need to check that the user actually entered 5 to 10 NUMBERS and no letters. Also a way with methods how to get the print out of the average to be in two decimal places. Thank you!!
package averagewithmethods; import java.util.Scanner;
public class AverageWithMethods { public static void main(String[] args) { String numbers = getInput(); double average = calculateAverage(numbers); printResult(numbers, average); } public static String getInput() { Scanner sc = new Scanner(System.in); System.out.println("Enter 5 to 10 numbers: "); String numbers = sc.nextLine(); return numbers; } public static double calculateAverage(String numbers){ String nums[] = numbers.split(" "); double d[] = new double[nums.length]; for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
