注意:把class后面的类名改成你新建的文件名,然后把下面的代码拷贝运行即可
public class case01 {
public static void main(String[] args) {
System.out.println("200个鸡蛋是" + 200/12 + "打");
System.out.println("剩余" + 200%12 + "个");
}
}
运行结果:
public class case09 {
// for 循环实现99乘法表
private static void showDo() {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "x" + i + "=" + j*i + "\t");
}
System.out.println();
}
}
// while 循环实现99乘法表
private static void showWhile() {
int i = 1;
while(i <= 9) {
int j = 1;
while(j <= i) {
System.out.print(j + "x" + i + "=" + j*i + "\t");
j++;
}
System.out.println();
i++;
}
}
// do/while 循环实现99乘法表
private static void showDoWhile() {
int i = 1;
do {
int j = 1;
do {
System.out.print(j + "x" + i + "=" + j*i + "\t");
j++;
} while(j <= i);
System.out.println();
i++;
}while(i <= 9);
}
public static void main(String[] args) {
System.out.println("\nfor循环写的:");
showDo();
System.out.println("\nwhile循环写的:");
showWhile();
System.out.println("\ndo/while循环写的:");
showDoWhile();
}
}
运行结果:
原文:https://www.cnblogs.com/amnotgcs/p/13769992.html