# 求两数之各

andy2u 2010-04-22 03:57:20

...全文
124 10 打赏 收藏 转发到动态 举报

10 条回复

youyouzhishen 2010-04-22
• 打赏
• 举报

``````
public class GetSun {

public static void main(String[] args) {
int sum = 0;
for(int i = 1; i <= 19; i++){
for(int j = 1; j <= 19; j++){
if((i + j == 20) && (i < j)){
System.out.println(i + " " + j);
}
}
}
}
}

``````

1 19
2 18
3 17
4 16
5 15
6 14
7 13
8 12
9 11
10 10
youyouzhishen 2010-04-22
• 打赏
• 举报

``````
public class GetSun {

public static void main(String[] args) {
int sum = 0;
for(int i = 1; i <= 19; i++){
for(int j = 1; j <= 19; j++){
if(i + j == 20){
if(!(i > j))
System.out.println(i + " " + j);
}
}
}
}
}

``````
sqd2010 2010-04-22
• 打赏
• 举报

public static void main(String[] args){
int[] a ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
for(int i=0;i<a.length/2;i++){
for(int j=0;j<a.length;j++){
if(a[i]+a[j]==20){
System.out.println(a[i]+","+a[j]);
}
}
}
}
ilrxx 2010-04-22
• 打赏
• 举报

[Quote=引用 5 楼 dazzlingwinter 的回复:]
Java code

int start = 1;
int end = 20 - start;
while(start <= end) {
System.out.println("<" + (start++) + " , " + (end--) + ">");
}
/*
<1 , 19>
<2 , 18>
<3 , 17>
<4 , 16>
<5 , 15>
<6 ……
[/Quote]
wutian4567268 2010-04-22
• 打赏
• 举报

class Test {

public static void main(String[] args) {
new Test().getNum(20);
}

public void getNum(int sum){
for (int i = 1; i < sum/2; i++) {
println("第" + i + "组：<" + i + "，" + sum-i + "〉" );
}
}
}
Dazzlingwinter 2010-04-22
• 打赏
• 举报

``````
int start = 1;
int end = 20 - start;
while(start < end) {
System.out.println("<" + (start++) + " , " + (end--) + ">");
}
/*
<1 , 19>
<2 , 18>
<3 , 17>
<4 , 16>
<5 , 15>
<6 , 14>
<7 , 13>
<8 , 12>
<9 , 11>
*/
``````
zhangtmd 2010-04-22
• 打赏
• 举报

int y=0;
int sum=20;
for(int x=1;x<=10;i++){
y=sum-x;
System.out.println("x="+x,"y="+y);
}
zfq642773391 2010-04-22
• 打赏
• 举报

``````
public static void main(String[] args) {
// TODO Auto-generated method stub

for(int i=1;i<=10;i++){
int j=20-i;
System.out.println("当i="+i+",j="+j+"时，他们的和为20！");
}
}
``````
andy2u 2010-04-22
• 打赏
• 举报

• 打赏
• 举报

62,568

• 近7日
• 近30日
• 至今