写一个方法,用一个for循环打印九九乘法表

lenotang 2008-06-15 07:55:04
大家集思广益:
/**
* 一个for循环打印九九乘法表
*/
public void nineNineMultiTable()
{
for (int i = 1,j = 1; j <= 9; i++) {
System.out.print(i+"*"+j+"="+i*j+" ");
if(i==j)
{
i=0;
j++;
System.out.println();
}
}
}
...全文
2835 57 打赏 收藏 转发到动态 举报
写回复
用AI写文章
57 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuyechuan 2011-11-06
  • 打赏
  • 举报
回复

public void nineNineMultiTable()
{
for (int i = 1,j = 1; j <= 9; i++) {
System.out.print(i+"*"+j+"="+i*j+" ");
if(i==j)
{
i=0;
j++;
System.out.println();
}
}
}

LucEaspe 2011-11-06
  • 打赏
  • 举报
回复
public class Nine2Nine {

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

for (int i = 1; i < 10; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + i + "=" + i * j + "\t");
}
System.out.println();
}
}
}
/*
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
*/
LucEaspe 2011-11-06
  • 打赏
  • 举报
回复

public class Nine2Nine {

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

for (int i = 1; i < 10; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + i + "=" + i * j + "\t");
}
System.out.println();
}
}
}
keyer114 2011-11-06
  • 打赏
  • 举报
回复
public void chengfabiao(){

for(int i=1;i<=9;i++){

for(int j=1;j<=i;j++){

System.out.print(i+"*"+j+"="+i*j+"\t");

}
System.out.println();
}

}
冰点小爱 2011-11-06
  • 打赏
  • 举报
回复
昨天ITAT好像是要一个FOR写,我写了两个FOR的,哎。一个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);
}
}


听可笑的承诺 2011-11-06
  • 打赏
  • 举报
回复
这个最好写了……
qqlwq123 2011-11-06
  • 打赏
  • 举报
回复
有什么用,时间复杂度一样没变,理解上反而没有嵌套好理解,代码又不见得简洁,完全是弊大于利。
kiss601459202 2011-10-28
  • 打赏
  • 举报
回复
[Quote=引用 45 楼 deltatang 的回复:]

俺脚着俺这个是性能最好的了,不给分没天理啊:

Java code

String[] list = {
"01",
"02 04",
"03 06 09",
"04 08 12 16",
"05 10 15 20 25",
"06 12 18 24 30 36",
"07 14 21 28 35 42 49",
"08 16 24 32 40 48 56 64",
"09 18 27 3……
[/Quote]

给你分就没天理了 你这个输出不了东西
nizhicheng 2011-10-28
  • 打赏
  • 举报
回复
哎呦~~真是精彩哈~~~
fensese 2011-10-28
  • 打赏
  • 举报
回复
public class Test {

public static void main(String[] args) {

for (int i = 1; i < 10; i++) {
for (int j =i; j < 10; j++) {
System.out.print(i + " * " + j + " = " + i * j + " ");
}
System.out.println();
}
}
}

結果:
1 * 1 = 1 1 * 2 = 2 1 * 3 = 3 1 * 4 = 4 1 * 5 = 5 1 * 6 = 6 1 * 7 = 7 1 * 8 = 8 1 * 9 = 9
2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18
3 * 3 = 9 3 * 4 = 12 3 * 5 = 15 3 * 6 = 18 3 * 7 = 21 3 * 8 = 24 3 * 9 = 27
4 * 4 = 16 4 * 5 = 20 4 * 6 = 24 4 * 7 = 28 4 * 8 = 32 4 * 9 = 36
5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45
6 * 6 = 36 6 * 7 = 42 6 * 8 = 48 6 * 9 = 54
7 * 7 = 49 7 * 8 = 56 7 * 9 = 63
8 * 8 = 64 8 * 9 = 72
9 * 9 = 81
fensese 2011-10-28
  • 打赏
  • 举报
回复
public class Test {

public static void main(String[] args) {

for (int i = 1; i < 10; i++) {
for (int j =i; j < 10; j++) {
System.out.print(i + " * " + j + " = " + i * j + " ");
}
System.out.println();
}
}
}

結果:
 1 * 1 = 1 1 * 2 = 2 1 * 3 = 3 1 * 4 = 4 1 * 5 = 5 1 * 6 = 6 1 * 7 = 7 1 * 8 = 8 1 * 9 = 9
2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18
3 * 3 = 9 3 * 4 = 12 3 * 5 = 15 3 * 6 = 18 3 * 7 = 21 3 * 8 = 24 3 * 9 = 27
4 * 4 = 16 4 * 5 = 20 4 * 6 = 24 4 * 7 = 28 4 * 8 = 32 4 * 9 = 36
5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45
6 * 6 = 36 6 * 7 = 42 6 * 8 = 48 6 * 9 = 54
7 * 7 = 49 7 * 8 = 56 7 * 9 = 63
8 * 8 = 64 8 * 9 = 72
9 * 9 = 81
makingjc 2011-10-28
  • 打赏
  • 举报
回复
public class Test {
public static void main(String[] args){
for(int i=1;i<=9;i++){
for(int j=1;j<i+1;j++){
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println("");
}
}
}
唐三角 2011-10-27
  • 打赏
  • 举报
回复
俺脚着俺这个是性能最好的了,不给分没天理啊


String[] list = {
"01",
"02 04",
"03 06 09",
"04 08 12 16",
"05 10 15 20 25",
"06 12 18 24 30 36",
"07 14 21 28 35 42 49",
"08 16 24 32 40 48 56 64",
"09 18 27 36 45 54 63 72 81",
};
for(int i = 0; i < 0; i++){
System.out.println(list[i]);
}

fubin438094754 2011-10-27
  • 打赏
  • 举报
回复
public void print() {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + " i =" + i *j + " ");
}
System.out.println();
}
}
伟明 2011-10-27
  • 打赏
  • 举报
回复
一定要一个吗?
paullbm 2011-10-27
  • 打赏
  • 举报
回复
。。。。。。。。。。
wangxin6302 2011-10-27
  • 打赏
  • 举报
回复
来个递归的,如有重复纯属巧合



public static void main(String[] ages) {
nineNineMultiTable(9);
}

public static void nineNineMultiTable(int i) {
if(i > 1) nineNineMultiTable(i-1);
for(int j=1;j<=i;j++) {
System.out.print(i + "*" + j + "=" + i*j + "\t");
}
System.out.println();
}
kiss601459202 2011-10-27
  • 打赏
  • 举报
回复
再来一个更生猛的 一个For都不用

public static void main(String[] args) {
getNum(9);
}

public static void getNum(int num) {
if (num == 1) {
System.out.println("1*1=1");
} else {
getNum(num - 1);
getN(1, num);
System.out.println();
}
}

public static void getN(int x, int y) {
if (x <= y) {
System.out.print(x + "*" + y + "=" + (x * y) + " ");
getN(x + 1, y);
}
}
kiss601459202 2011-10-27
  • 打赏
  • 举报
回复
哈哈 一次循环99乘法 我也来一个


public static void getNum(int num) {
if (num == 1) {
System.out.println("1*1=1");
} else {
for (int i = 1; i <= num; i++) {
System.out.print(i + "*" + num + "=" + (i * num) + " ");
}
System.out.println();
getNum(num-1);
}
}

public static void main(String[] args) {
getNum(9);
}
ganyusheng0604 2011-10-27
  • 打赏
  • 举报
回复
错了,应该是:

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

}
}
}
}

加载更多回复(37)

62,630

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧