public class stuff {
public static void main ( String [] args ) {
int n1 = 10;
int n2 = 4;
int r = n1%n2;
System.out.println ( n1 + " " + n2 + " " + r );
if (r>=1) {
n2 = n1;
n1 = r;
System.out.println ( n1 + " " + n2 + " " + r );
}
}
}
这是我到目前为止所拥有的。我想用n2替换n1,用r。
替换n2它给了我这个:
10 4 2
2 10 2
对于第一部分,n1 = 10,n2 = 4且r = 2.对于第二部分,n1 = 2,n2 = 10且r = 2.我想要第二部分n1 = 4& n2 = 2.有什么想法吗?除了代码之外,我们将非常感谢解释。
答案 0 :(得分:1)
看起来像你想要的
n1 = n2; // this would change n1 from 10 to 4
n2 = r; // this would change n2 from 4 to 2
答案 1 :(得分:0)
我可能不理解你的问题,但我会尽力帮助你。
这很简单。首先,你想要n1 = n2(此时n2为4)。
然后,n2 = r;
像这样:
public class stuff {
public static void main ( String [] args ) {
int n1 = 10;
int n2 = 4;
int r = n1%n2;
System.out.println ( n1 + " " + n2 + " " + r );
if (r>=1) {
n1 = n2;
n2 = r;
System.out.println ( n1 + " " + n2 + " " + r );
}
}
我认为你想要完成的是一个循环...你想在控制台中打印输出只要r大于1?如果是这种情况,请告诉我,我会向您解释。