首先,我正在学习Java,但我仍然很新,所以复杂的代码将会超越我的头脑.
当我下载一个.jar文件说安装mod到Minecraft并双击它时,它不会运行.加载轮持续两秒钟然后停止,没有其他事情发生.我知道的.jar设置正确,因为它使用命令运行cmd
cd "wherever the file is"
java -jar "file name".jar
Run Code Online (Sandbox Code Playgroud)
所以我已经尝试使用java\jdk1.7.0_25\jre\bin中的默认程序设置为javaw.exe来运行它.没有任何反应.因此文件关联设置在正确的位置.我在这里不知所措.
这还不错,因为我仍然可以通过cmd运行它们,但是当我到书中关于jar的部分时,我希望能够通过Windows资源管理器GUI运行它,这就像使用的一半好处我能看到的.jar文件.
是否可能是注册表错误?我已经看到了很多关于这个问题的问题,但是大多数问题似乎都是设置.jar的问题,我没有这样做,而且我认为这不是这种情况.
我有Windows Vista 64位.
如果我不够具体,请随时问.
使用Javadocing时,我不知道您是否应该明确说明参数是类型String
还是int
。例如
/**
* This method does something
* @param foo an object of type Foo
* @param abc the number of doors, of type int
* @return the number of windows, of type int
*/
public int doSomething(Foo foo, int abc) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
我使用eclipse,因此当我查看Javadoc的用户端时,所有内容都有类型说明,而eclipse会告诉我何时使用了错误的类型引用。
那么,我应该包括上面的类型描述,还是Javadoc / compiler帮我解决这个问题?
在CS中,我们必须模拟一个HP 35计算器,所以我查找了e ^ x的总和[在这种情况下,'^'表示"对于权力"].公式是sum n=0 to infinity ( (x^n) / (n!) )
在我的实现中,第一个for循环是求和循环:1 + x + x^2 /2! + x^3 /3! + ...
,第二个for循环用于单独乘以该项x
,以便不溢出double:... + (x/3) * (x/2) * (x/1) + ...
关于时间复杂度,第一个for循环仅用于确保必要的精度,但第二个for循环用于乘以项.这两个循环都不受x大小的直接影响,所以我不知道如何计算这个算法的时间复杂度; 我怀疑它是n ln(n).我该如何计算/该算法的时间复杂度是多少?
public class TrancendentalFunctions {
private static final double ACCURACY = .000000000000001;
public static double exp(double x) {
// if larger than 709, throw overflow error
double result = 1; // result starts at one is important
for(int i=1; i < …
Run Code Online (Sandbox Code Playgroud) 我对舍入算法感到好奇,因为在CS中我们必须模拟HP35而不使用数学库.我们在最终版本中没有包含舍入算法,但无论如何我想要这样做.
public class Round {
public static void main(String[] args) {
/*
* Rounds by using modulus subtraction
*/
double a = 1.123599;
// Should you port this to another method, you can take this as a parameter
int b = 5;
double accuracy = Math.pow(10, -b);
double remainder = a % accuracy;
if (remainder >= 5 * accuracy / 10) // Divide by ten is important because remainder is smaller than accuracy
a += accuracy;
a -= remainder;
/* …
Run Code Online (Sandbox Code Playgroud)