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();
}
}
There's my program if that helps,
The manifest says the following:
Manifest-Version: 1.0
Main-Class: NumberAverager
It's just a short program to try to do this, but I don't know what else I have to do to make it work, I'm not sure how to run it from the command line to try it that way, and upon double clicking it the mouse loads for a second and nothing happens
thanks
I'm very new to java, only a beginning semester under my belt, so I need very detailed explanations on how to do this, thanks again
You need a UI for it to display something when you double click. Otherwise it will run the code but its not gonna display anything.
使用java -jar
在命令提示符下执行jar文件。
java -jar C:/path/to/jar/your_jar_file.jar
java -jar <PATH_TO_YOUR_JAR_FILE>
并确保$ PATH中有java
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.