So führen Sie die Windows -Eingabeaufforderung aus, wenn Sie eine JAR -Datei öffnen [Duplikat]Java

Java-Forum
Anonymous
 So führen Sie die Windows -Eingabeaufforderung aus, wenn Sie eine JAR -Datei öffnen [Duplikat]

Post by Anonymous »

Ich bin ein Java -Programmierer für Anfänger mit ungefähr einer Woche Java -Erfahrung und etwa drei Wochen C# -Erfahrung. Ich arbeite an meinem ersten grundlegenden Projekt und habe es in eine JAR -Datei exportiert, die über die Windows -Eingabeaufforderung geöffnet werden kann. Ich frage mich, wie ich das Glas den Eingabeaufforderung automatisch öffnen kann, wenn Sie es öffnen. Das Projekt besteht aus einem einfachen Taschenrechner, der über das Intelij -Laufterminal interagiert. Hier ist die Haupt -Java -Datei: < /p>
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
// Make it automatically open Command prompt
float[] inputVariables = new float[4];
calculator(inputVariables);
}
public static void calculator(float[] loopVariables) {

System.out.println("WARNING: Inputting a non true or false value, or a non number when asked to will crash the program! (For now)");

Scanner inputScanner = new Scanner(System.in);

while (true) {
float z = 0;
System.out.println("Select an operation: (Addition: +, Subtraction: -, Multiplication: *, Division: /, Modulo: %, Power: ^, Absolute Value: |, Round: ~");
String operation = inputScanner.next();
switch (operation) {
case "+", "-", "*", "/", "%", "^", "|", "~" -> {

}
default -> {
System.out.println("This is not a valid operation.");
continue;
}
}

float x;
if (loopVariables[1] == 0) {
System.out.println("Input x:");
x = inputScanner.nextFloat();
} else {
x = loopVariables[0];
System.out.println("x = " + x);
}

float y = 0;
switch (operation) {
case "+", "-", "*", "/", "%", "^" -> {
System.out.println("Input y:");
y = inputScanner.nextFloat();
}
case "~" -> {
System.out.println("Round up, down or auto: (+ or -)");
operation = inputScanner.next();
switch (operation) {
case "+" -> {
System.out.println("+~" + x + " = " + (Math.ceil(x)));
z = (float)Math.ceil(x);
operation = "~";
}
case "-" -> {
System.out.println("-~" + x + " = " + (Math.floor(x)));
z = (float)(Math.floor(x));
operation = "~";
}
default -> {
System.out.println("This is not a valid operation.");
continue;
}
}
}
case "|" -> {
}
}
switch (operation) {
case "+" -> {
System.out.println(x + " + " + y + " = " + (x + y));
z = x + y;
}
case "-" -> {
System.out.println(x + " - " + y + " = " + (x - y));
z = x - y;
}
case "*" -> {
System.out.println(x + " * " + y + " = " + (x * y));
z = x * y;
}
case "/" -> {
System.out.println(x + " / " + y + " = " + (x / y));
z = x / y;
}
case "%" -> {
System.out.println(x + " % " + y + " = " + (x % y));
z = x % y;
}
case "^" -> {
System.out.println(x + "^" + y + " = " + (float)(Math.pow(x, y)));
z = (float)Math.pow(x, y);
}
case "|" -> {
System.out.println("|" + x + "| = " + (Math.abs(x)));
z = Math.abs(x);
}
case "~" -> {

}
default -> {
System.out.println("This is not a valid operation.");
continue;
}
}
System.out.println("Would you like to continue with the result as x? (true or false)");
boolean finish = inputScanner.nextBoolean();
float hasLooped;
if (finish) {
hasLooped = 1;
loopVariables[0] = z;
loopVariables[1] = hasLooped;
continue;
} else {
System.out.println("Would you like to continue without the result as x? (true or false)");
finish = inputScanner.nextBoolean();
}
hasLooped = 0;
loopVariables[1] = hasLooped;
if (!finish) {
System.out.println("Ending Calculator.");
break;
}
}
}
}
< /code>
Ziel ist es, eine Singular -JAR -Datei zu haben, die beim Double -Klick die Eingabeaufforderung öffnet und das Programm ausführt und nicht die Verwendung der Eingabeaufforderung erfordert, um geöffnet zu werden. Diese Frage ist ähnlich, die angegebene Antwort erfordert jedoch eine Stapeldatei und eine JAR -Datei, und ich brauche eine, für die nur eine JAR -Datei erforderlich ist. Alle anderen Fragen haben Antworten, die entweder nicht funktionieren oder mehr als eine Datei erfordern. Öffnen Sie externe Dateien mit Java "," So führen Sie die Windows -Eingabeaufforderung mit Java aus ", aber ich kann nichts finden, was funktioniert. und nichts.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post