用for循环输出1——1000之间能被5整除的数,并且每行输出3个
package com.wen.struct;
public class ForDemo03 {
public static void main(String[] args) {
//用while或for循环输出1——1000之间能被5整除的数,并且每行输出3个
for (int i = 0; i <= 1000; i++) {
if (i%5==0){
System.out.print(i+"\t");
}
if (i%(5*3)==0) { //每3个数字换一行
System.out.println();
//System.out.print("\n");
}
}
//print 输出完不会换行
//println 输出完会换行
}
}
打印九九乘法表
package com.wen.struct;
public class ForDemo04 {
public static void main(String[] args) {
/*
* 步骤
* 1. 先打印第一列
* 2. 把固定的1再用一个循环包起来
* 3. 去掉重复项,i<=j
* 4. 调整样式*/
for (int j = 1; j <= 9; j++) {
for (int i = 1; i <=j; i++) {
System.out.print(i + "*" + j + "=" + i*j + "\t");
}
System.out.println();
}
}
}