今天朋友讨论的一个小代码 输入小的数字 还可以运行 大一点的数字就会报错
请问大家该如何修改?!谢谢!换一种更好的写法也可以!public class jianmo {
static long count = 0; public static long jech(long a) {
long s = 1;
for (long i = a; i > 0; i--)
s *= i;
return s; } public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
int t;
int x;
int y;
jianmo j = new jianmo();
for (t = 0; t <= n; t++)
for (x = 0; x <= n; x++)
for (y = 0; y <= n / 2; y++) {
if (x + 2 * y == n & x + y == t) {
try{ count = count + j.jech(t) / (j.jech(t - x) * j.jech(x)); }catch(ArithmeticException e){
System.out.println(e.getMessage());
}
// System.out.println(x + "," + y + "," + count+","+t);
}
}
System.out.println(count);
}
}
请问大家该如何修改?!谢谢!换一种更好的写法也可以!public class jianmo {
static long count = 0; public static long jech(long a) {
long s = 1;
for (long i = a; i > 0; i--)
s *= i;
return s; } public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
int t;
int x;
int y;
jianmo j = new jianmo();
for (t = 0; t <= n; t++)
for (x = 0; x <= n; x++)
for (y = 0; y <= n / 2; y++) {
if (x + 2 * y == n & x + y == t) {
try{ count = count + j.jech(t) / (j.jech(t - x) * j.jech(x)); }catch(ArithmeticException e){
System.out.println(e.getMessage());
}
// System.out.println(x + "," + y + "," + count+","+t);
}
}
System.out.println(count);
}
}
解决方案 »
- 50分:MyEclipse 编好的程序如何打包?谢谢。
- oracle 11g jdbc lib 里面的包
- String s1=new String("hello");String s2=new String("hello");创建对象问题
- javaGUI编程在一个类里怎么改变另一个类中设置的组件中的内容?
- 报错!帮看看!!
- 如何将窗体画成非矩形窗体!分不够在加
- 各位csdn上的高手哪个有联通的spip网关的源代码呀,用java写的,如果没有可以进来知道一下吗
- 请深圳的朋友过来看下!!!
- 代码是对的,但就是编译通不过,谁能告诉我该怎么弄?
- 谁能告诉我,用那个java编辑器最好
- 救命关于打jar包的问题 好几个文件
- 请各位帮我看一下,为什么这里有错~~谢谢,关于JTable的
具体参见jdk