这是我第一次编写多个方法,我需要一个程序来获取用户输入的一些双值并找到平均值。这是我到目前为止所尝试的,它打印出来:
Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at Lab5.main(Lab5.java:11)
import java.util.*;
public class Lab5
{
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int count = 0;
double sum = scan.nextDouble();
count = scan.nextInt();
printLineAverage(sum, count++);
}
public static void printLineAverage(double sum, int count)
{
double average = sum/count;
System.out.println(average);
}
}