如果用Java编程。实现输出如下一个9×9乘法表?
答案:4 悬赏:30 手机版
解决时间 2021-11-27 07:35
- 提问者网友:戎马万世
- 2021-11-26 18:50
如果用Java编程。实现输出如下一个9×9乘法表?
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-11-26 19:07
public class Test{
public static void main(String[] args) {
System.out.print(" ");
for(int n = 1;n <= 9;n++) {
System.out.print(n+" ");
}
System.out.println();
for(int i = 1;i <= 9;i++) {
System.out.print(i+" ");
for (int j = 1;j <= 9 ;j++ ) {
System.out.print(i*j + " ");
}
System.out.println();
}
}
}
public static void main(String[] args) {
System.out.print(" ");
for(int n = 1;n <= 9;n++) {
System.out.print(n+" ");
}
System.out.println();
for(int i = 1;i <= 9;i++) {
System.out.print(i+" ");
for (int j = 1;j <= 9 ;j++ ) {
System.out.print(i*j + " ");
}
System.out.println();
}
}
}
全部回答
- 1楼网友:罪歌
- 2021-11-26 21:56
循环输出而已,两个循环就能搞定
- 2楼网友:持酒劝斜阳
- 2021-11-26 20:53
public class Test {
public static void main(String[] args) {
System.out.print(" 1 2 3 4 5 6 7 8 9");
for(int i = 1; i <= 9; i++) {
System.out.println();
System.out.print(" " + i + " ");
for(int j = 1; j <= 9; j++) {
if(i*j > 9){
System.out.print(i*j + " " );
}else{
System.out.print( i*j + " ");
}
}
}
}
}
public static void main(String[] args) {
System.out.print(" 1 2 3 4 5 6 7 8 9");
for(int i = 1; i <= 9; i++) {
System.out.println();
System.out.print(" " + i + " ");
for(int j = 1; j <= 9; j++) {
if(i*j > 9){
System.out.print(i*j + " " );
}else{
System.out.print( i*j + " ");
}
}
}
}
}
- 3楼网友:第幾種人
- 2021-11-26 20:10
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (i == 0) {
if (j == 0) {
System.out.print(" ");
}else
System.out.print(j + " ");
} else if (j == 0)
System.out.print(i + " ");
else
System.out.print(i * j + " ");
}
System.out.println();
}
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (i == 0) {
if (j == 0) {
System.out.print(" ");
}else
System.out.print(j + " ");
} else if (j == 0)
System.out.print(i + " ");
else
System.out.print(i * j + " ");
}
System.out.println();
}
}
输出不是很美观,将就了吧.
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯