0
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

bassandguitar
  • 189
  • 2
  • 2
  • 8

3 Answers3

0

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.

Here is a tutorial on making a GUI

RisingSun
  • 1,693
  • 27
  • 45
0

Use java -jar to execute your jar file in command prompt.

java -jar C:/path/to/jar/your_jar_file.jar 
Stanley
  • 5,057
  • 4
  • 34
  • 44
0
java -jar <PATH_TO_YOUR_JAR_FILE>

and make sure java is there in $PATH

Rahul
  • 15,979
  • 4
  • 42
  • 63
  • I typed in java -jar C:\Users\Ben\Desktop\NumberAverager.jar What do you mean make sure java is there? – bassandguitar Dec 20 '12 at 06:52
  • on your console, type java --version. It should give an output specifying the java version. If not, make sure jdk is installed properly – Rahul Dec 20 '12 at 06:55
  • I don't understand what you mean by type it on my console, I'm sorry, do you mean cmd line? – bassandguitar Dec 20 '12 at 06:57
  • It says: java version "1.7.0_10" Java SE Runtime Environment Java HotSpot 64-Bit Server VM – bassandguitar Dec 20 '12 at 07:00
  • the program runs from the cmd prompt I just don't know how to make it run by double clicking it – bassandguitar Dec 20 '12 at 07:03
  • Eclipse has an option to package required libraries into the runnable jar. File -> Export... Choose runnable jar and click next. The runnable jar export window has a radio button where you can choose to package the required libraries into the jar. – Rahul Dec 20 '12 at 07:13
  • The double click thing should work i think. If you are on Windows, then Right Click on the jar itself, go to Open With.. and make sure the selected program is called something like Java(TM) Platform SE Binary. If someting goes wrong open the Java console and paste the error for us to help (go to Java Control Panel, in Control Panel on Windows, Advanced tab, Java console and check Show console). – acostache Dec 20 '12 at 07:13
  • Nothing happens when I double click the program, I don't know why, is it because there is no GUI stuff, someone else on here said that? – bassandguitar Dec 20 '12 at 07:20