import java.util.Scanner;
public class NumberAverager {
/**
* Averages Inputted Numbers
*/
public static void main(String[] args) {
int num1;
int total = 0;
int count = 0;
//int[] numArray = new int[count];
String input;
Scanner keyboard = new Scanner(System.in);
do
{
if (count == 0)
{
System.out.println("Please enter the first number you wish to average.");
input = keyboard.nextLine();
}
count++;
System.out.println("Please enter your next number or 'calculate' to find the average.");
input = keyboard.nextLine();
try
{
num1 = Integer.parseInt(input);
total = total + num1;
//numArray[count]=num1;
}
catch (NumberFormatException e)
{
System.out.println("You entered " + count + " numbers.");
System.out.println("The average is " + (float)total/count);
//System.out.println(numArray[count]);
input = "calculate";
}
} while (input!= "calculate");
keyboard.close();
}
}
有我的程序,如果有帮助的话,
清单显示以下内容:
Manifest-Version: 1.0
Main-Class: NumberAverager
这只是一个尝试执行此操作的简短程序,但我不知道我还需要做什么才能使其工作,我不知道如何从命令行运行它以尝试这种方式,并且在双重单击它鼠标加载一秒钟,没有任何反应
谢谢
我对java很陌生,只有一个开始的学期,所以我需要非常详细的解释如何做到这一点,再次感谢