如题所述
/*
需求:在控制台输出九九乘法表。
首先我们写出九九乘法表:
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*9=9 2*9=18 3*9=27 ...
我们先把这个九九乘法表看出是这样的一个形状:
*
**
***
****
*****
******
*******
********
*********
注意:
'\x' x表示任意,这种做法叫转移字符。
'\t' tab键的位置
'\r' 回车
'\n' 换行
*/
class ForForDemo3 {
public static void main(String[] args) {
for(int x=0; x<9; x++) {
for(int y=0; y<=x; y++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("--------------");
//为了使用数据,我们从1开始
for(int x=1; x<=9; x++) {
for(int y=1; y<=x; y++) {
System.out.print(y+"*"+x+"="+y*x+"\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*9=9 2*9=18 3*9=27 ...
我们先把这个九九乘法表看出是这样的一个形状:
*
**
***
****
*****
******
*******
********
*********
注意:
'\x' x表示任意,这种做法叫转移字符。
'\t' tab键的位置
'\r' 回车
'\n' 换行
*/
class ForForDemo3 {
public static void main(String[] args) {
for(int x=0; x<9; x++) {
for(int y=0; y<=x; y++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("--------------");
//为了使用数据,我们从1开始
for(int x=1; x<=9; x++) {
for(int y=1; y<=x; y++) {
System.out.print(y+"*"+x+"="+y*x+"\t");
}
System.out.println();
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2014-08-06
直接在每个算数后面加上“\t”就是制表符可以让他们之间间隔一个tab位,这样就可以对其了
第2个回答 2014-08-06
public class Test //9*9表
{
public static void main(String args[])
{
int i=1;
while(i<10)
{
int j=1;
while(j<=i)
{
System.out.print(j+"*"+i+"="+i*j+'\t');
j++;
}
i++;
System.out.print('\n');
}
}
}
{
public static void main(String args[])
{
int i=1;
while(i<10)
{
int j=1;
while(j<=i)
{
System.out.print(j+"*"+i+"="+i*j+'\t');
j++;
}
i++;
System.out.print('\n');
}
}
}
这样就可以啦~
内外循环的i 和 j 的位置先后注意下~
本回答被网友采纳第3个回答 2014-08-06
你 把结果都按2位显示,不够2位的补0或者空格追问
不明白,能给代码解释下吗
追答if (i*j < 10) {
System.out.print(j+"*"+i+"= "+i*j+' ');
} else {
System.out.print(j+"*"+i+"="+i*j+' ');
}
我以前是用string format做出来的,可是忘了,你知道怎么做吗
追答String sendDataString = String.format("%d*%d=%s",(Object[]) sendData);
本回答被提问者采纳