1.使用*打印4x5的矩形
package month9;
public class forfordemo {
public static void main(String[] args){
test();
}
public static void test(){
int i = 1;
int j = 1;
for(i = 1; i <= 4; i++){
for(j = 1; j <= 5; j++){
System.out.print("*");
}
System.out.println();
}
}
}
在java中,使用print打印后不换行,而使用println打印后换行
2.打印九九乘法表
package month9;
public class forfordemo {
public static void main(String[] args) {
printTable();
}
public static void printTable() {
int i = 1;
int j = 1;
for(i = 1;i<=9;i++){
for(j = 1;j<=i;j++){
System.out.print(j + "x" + i + "=" + j*i + "\t");
//System.out.printf("%dx%d=%d\t",j,i,j*i);
}
System.out.println();
}
}
}