如何让这些Java代码在Eclipse之外运行?
import java.util.*;
public class Calculations {
public static void main(String[] args) {
Scanner console = new Scanner (System.in);
System.out.println("So... you want to figure out what the Hypotenuse of any Right Triangle is but your to");
System.out.println("lazy to do it your self huh..Sigh... Ok well, At least your being honest about it :)");
System.out.println();
System.out.println("Lets do this...Pythagoreom Style");
System.out.println();
System.out.println("First things first, whats your Sine? And no I don't mean if your an Aquarious or");
System.out.print("some shit like that, I mean your Y value or the first side of your triangle? ");
double side1 = console.nextDouble();
System.out.println();
System.out.println("Okayyyy and now as any good math teacher would say, Whats your Cosine or X value?");
System.out.print("(You might as well learn some Trigonometry while your taking the easy way out) ");
double side2 = console.nextDouble();
System.out.println();
System.out.println("Ok give me a minute... ");
System.out.println();
System.out.println();
System.out.print("Oh, by the way whats your favorite food? ");
String x = console.next();
System.out.println();
System.out.println();
double hypotonuse = Math.sqrt((Math.pow(side1,2)+ Math.pow(side2,2)));
System.out.println("So you favorite food is " + x + " Huh...well...THATS BESIDES THE POINT!!! BACK TO MATH!!!");
System.out.println();
double sum = (Math.pow(side1,2)+Math.pow(side2,2));
System.out.println("So if your First Side is "+side1 + " and we square that and your Second Side is " + side2+ " and we square that too,");
System.out.println();
System.out.println("we can add those sides together to get our sum of "+sum+" Finally we can square root "+sum+ " and Viola!");
System.out.println();
System.out.println("Pythagoras says your Hypotenuse is "+ hypotonuse);
System.out.println();
System.out.println();
System.out.println("HHHAAAZZZAAAAA!!!! FOR MATH!!! HAAAZZZAAAA for Pythagoreum!!!");
System.out.println();
System.out.println();
System.out.println("Oh, and P.S.");
System.out.println();
System.out.println("I'm just kidding, I care about your favorite food,");
System.out.println();
System.out.println("Here's a pyramid type thing of it built by a ratio given by your Hypotenuse :)");
System.out.println();
System.out.println();
for( int i =1; i <=hypotonuse; i++)
{
for (int w = 1; w<=(hypotonuse-i); w++)
{
System.out.print(" ");
}
for(int v=1; v<= (2*i-1); v++)
{
System.out.print(" "+ x );
}
System.out.println();
}
}
}
答案 0 :(得分:1)
在Eclipse中,转到文件&gt;导出&gt; java&gt; Runnable jar文件&gt;启动conf pick主类。出口目的地。导出后的文件目的地&gt;完成
之后你可以用命令行运行jar(所以你可以看到你的控制台)在搜索中键入cmd并进入你的jar所在的目录运行jar ..运行jar文件的命令 java - jar nameofjar.jar
答案 1 :(得分:0)
已经从内存中写了这个,因为我现在无法访问eclipse。
右键单击项目
导出
可执行/可运行的jar文件。
(接下来的两个步骤可能是错误的顺序)
确保为main方法选择正确的类。
选择文件位置和文件名
点击完成/完成
浏览你的jar,运行它
答案 2 :(得分:0)
虽然您可以从Eclipse导出该类并运行它,但我建议您从第一原则开始理解该过程。在您了解了基础知识并处理复杂应用程序之后,您可以使用像ant或maven这样的构建工具来生成jar文件并运行它。
第一原则:
JAVA_HOME/bin
添加到PATH,以便工作。Calculations.java
文件的目录。javac Calculations.java
Calculations.class
文件。java Calculations
在Eclipse外部运行已编译的类。是的,您不能在命令中使用.class
扩展名。jar -cvf calculations.jar *
java -jar calculations.jar Calculations
答案 3 :(得分:0)
您始终可以从命令行
运行它答案 4 :(得分:0)