JAVA用while和do while分别写出99乘法表
publicclasschengfabiao{publicstaticvoidmain(String[]args){inta,b;for(a=1;a<=9;a++){fo...
public class chengfabiao {
public static void main(String[] args) {
int a,b;
for(a=1;a<=9;a++){
for(b=1;b<=9;b++)
System.out.print(a+"*"+b+"="+a*b+"\t");
System.out.print("\n");}}}
这是我用for循环写的乘法表,请分别用while和do while 写出个运行结果相同的代码 展开
public static void main(String[] args) {
int a,b;
for(a=1;a<=9;a++){
for(b=1;b<=9;b++)
System.out.print(a+"*"+b+"="+a*b+"\t");
System.out.print("\n");}}}
这是我用for循环写的乘法表,请分别用while和do while 写出个运行结果相同的代码 展开
1个回答
展开全部
很简单,几乎不用改什么。
------------------- while -------------------
int a = 0;
while (++a < 10) {
int b = 0;
while (++b < 10) {
System.out.print(a + "*" + b + "=" + (a*b) + "\t");
}
System.out.println();
}
------------------- do -- while -------------------
int a = 1;
do {
int b = 1;
do {
System.out.print(a + "*" + b + "=" + (a*b) + "\t");
} while (b < 10);
System.out.println();
} while (a++ < 10);
------------------- while -------------------
int a = 0;
while (++a < 10) {
int b = 0;
while (++b < 10) {
System.out.print(a + "*" + b + "=" + (a*b) + "\t");
}
System.out.println();
}
------------------- do -- while -------------------
int a = 1;
do {
int b = 1;
do {
System.out.print(a + "*" + b + "=" + (a*b) + "\t");
} while (b < 10);
System.out.println();
} while (a++ < 10);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询