添加代码!完善此题!
java吧
全部回复
仅看楼主
level 9
丶渲目 楼主
小弟的作业,一个小题目,几乎做完了,但是还是有点问题,求大神帮我加段代码,完善它
2013年04月19日 08点04分 1
level 9
丶渲目 楼主
打印的答案有很多重复的,我要怎么把它们去掉?
2013年04月19日 08点04分 2
level 9
丶渲目 楼主

public class Ti8 {
/** * 考虑方程式:a^3 + b^3 = c^3 + d^3其中:“^”表示乘方。a、b、c、d是互不相同的小于30的正整数。这个方程有很多解。比如:a = 1,b=12,c=9,d=10 就是一个解。因为:1的立方加12的立方等于1729,而9的立方加10的立方也等于1729。当然,a=12,b=1,c=9,d=10 显然也是解。如果不计abcd交换次序的情况,这算同一个解。你的任务是:找到所有小于30的不同的正整数解。把a b c d按从小到大排列,用逗号分隔,每个解占用1行。比如,刚才的解输出为:1,9,10,12不同解间的顺序可以不考虑。 */
public static boolean fa(int a,int b,int c,int d){
if(Math.pow(a, 3)+Math.pow(b, 3)==Math.pow(c, 3)+Math.pow(d, 3)){return true;}
return false;
}
public static int[] paixu(int a,int b,int c,int d){
int array[]={a,b,c,d};
for(int i=0;i<array.length;i++){
for(int j=i;j<array.length;j++){
if(array[i]>array[j]){
int temp;temp=array[i];
array[i]=array[j];
array[j]=temp;
}}}
return array;}
public static void main(String[] args) {
for(int a=0;a<31;a++){
for(int b=0;b<31;b++){
for(int c=0;c<31;c++){
for(int d=0;d<31;d++){
if(a!=b &&a!=c&& a!=d && b!=c && b!=d&& c!=d && fa(a,b,c,d)){
int aaa[]=paixu(a,b,c,d);
for(int aa:aaa){System.out.print(aa+" ");}
System.out.println();
}}}}}}
}
2013年04月19日 08点04分 3
在 for(int b=0;b<31;b++){下面加上if (b <= a) continue;[$1]在 for(int c=0;c<31;c++){ 下面加上if (c <= a) continue;在 for(int d=0;d<31;d++){下面加上 if (d <= c) continue;
2013年04月19日 09点04分
level 9
丶渲目 楼主
大叔大婶,大神,在哪?
2013年04月19日 08点04分 4
人呢?
2013年04月19日 08点04分
level 9
丶渲目 楼主
我坐等了!
2013年04月19日 08点04分 5
level 9
丶渲目 楼主
大神,求教!
2013年04月19日 08点04分 6
level 9
丶渲目 楼主
有帮忙看一下的吗?
2013年04月19日 08点04分 7
level 9
丶渲目 楼主
哎呀,好伤心啊
2013年04月19日 08点04分 8
level 9
丶渲目 楼主
没有人啊
2013年04月19日 08点04分 9
level 9
丶渲目 楼主
感觉不会再爱了
2013年04月19日 08点04分 10
level 5
刚看到,等我改完给你回,等会
2013年04月19日 09点04分 12
在呢
2013年04月19日 09点04分
level 5
人在么? 不在我就不回了
2013年04月19日 09点04分 14
在啊
2013年04月19日 09点04分
level 8
[嘘]
2013年04月19日 10点04分 15
多大事
2013年04月19日 11点04分
level 9
丶渲目 楼主
在想怎么加代码?我的代码可能太乱了
2013年04月19日 11点04分 16
level 9
丶渲目 楼主
大神晚上去哪里了
2013年04月19日 11点04分 17
1