【Java程序设计】用while和do-while两种不同的形式输出九九乘法表

While:

class sixth_first {
    
    
	public static void main(String[] args) {
    
    
		int i = 1,j = 1;
		int temp;
		while(i != 10 && j != 10){
    
    
			temp = j;
			if(i <= j)
				System.out.print(i + "*" + j + "=" + i*j + "\t");
			i ++;
			if(j < i){
    
    
				System.out.println();
				temp++;
				i = 1;
				j = temp;
			}
		}
	}
}

Do-While:

class sixth_second {
    
    
	public static void main(String[] args) {
    
    
		int i = 1,j = 1;
		int temp;
		do{
    
    
			temp = j;
			if(i <= j)
				System.out.print(i + "*" + j + "=" + i*j + "\t");
			i ++;
			if(j < i){
    
    
				System.out.println();
				temp++;
				i = 1;
				j = temp;
			}
		}while(i != 10 && j != 10);
	}
}

结果如下:
在这里插入图片描述

おすすめ

転載: blog.csdn.net/passer__jw767/article/details/111396990