簡體   English   中英

我在eclipse上有一個程序,並將其導出為可運行的JAR文件,如何雙擊運行它?

[英]I have a program on eclipse and exported it as a runnable JAR file, how do I run it on a double click?

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還是很陌生,只是剛開始的一個學期,所以我需要有關如何執行此操作的非常詳細的說明,再次感謝

您需要一個UI才能在雙擊時顯示某些內容。 否則它將運行代碼,但不會顯示任何內容。

這是有關制作GUI的教程

使用java -jar在命令提示符下執行jar文件。

java -jar C:/path/to/jar/your_jar_file.jar 
java -jar <PATH_TO_YOUR_JAR_FILE>

並確保$ PATH中有java

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM