用Java写一个方法,用一个for循环打印九九乘法表 要求:只能用1个for循环

如题所述

程序如下
public class Chengfabiao {

public static void main(String[] args) {

String output = "9 9 乘法表\n";
output += "~~~~~~~~~~~~~~~~~~~~~\n";
for (int i = 1, j = 1; i < 10; j++) {
output += "\t"+ j + "*" + i + "=" + j * i;
if (i == j) {
j = 0;
i++;
output += "\n";
}
}
System.out.println(output);
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-10-26
public class chengfabiao {
public static void main(String[] args){
//9X9乘法表
//定义其中一个乘数,取值范围是1-9 ,循环条件是i++
for(int i=1;i<=9;i++){
//定义另一个乘数,取值范围也是1-9 ,循环条件是j++
for(int j=1;j<=i;j++){
//由于j<=i,输出时将j写在前边,为了好看后边加上制表位:"\t"
System.out.printj+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
}
第2个回答  2010-10-24
这是标准的九九乘法表:刚做的!呵呵
public final class one_for {

/**
* @param args
*/
public static void main(String[] args) {
for (int i = 1, j = 1; i <= 9; j++) {
System.out.print(j + "*" + i + "=" + j * i + " \t");
if (i == j) {
i++;
j = 0;
System.out.println();
}

}
}
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网