import java.util.*;
//使用for循环输出三位数中所有能被6整除的数,并且每行输出5个
class for1{
public static void main(String[] args){
int count = 0;
for(int i=100;i<=999;i++){
if(i%6==0){
System.out.print("\t"+i); //如果是println()则会纵向输出五个一组
count++;
if(count%5==0){
System.out.println(); //如果是print()则会出现编译错误 对于print(没有参数), 找不到合适的方法
}
}
}
}
}
/*输出效果如下,要求每次输出一个*
******
******
******
*/
class For2{ //第一种方法
public static void main(String[] args){
for(int i=1;i<=18;i++){ //三行总共18个
System.out.println("*");
if(i%6==0){
System.out.println(); //表示换行
}
}
}
}
class For3{ //第二种双重for循环
public static void main(String[] args){
for(int o=1;o<=3;o++){
for(int i=1;i<=6;i++){
System.out.print("*");
}
System.out.println();
}
}
}
//使用while循环完成输出50-100内所有奇数
class While1{
public static void main(String[] args){
int i = 51;
while(i<=100){
if(i%2 != 0){
System.out.println(i);
}
i++;
}
}
}
//练习:使用while循环完成输出所有三位数中能被四整除的数,并且每行显示五个
//第一种方法
class While2{
public static void main(String[] args){
int i = 100,count = 0;
while(i <= 999){
if(i % 4 == 0){
System.out.print(i+"\t");
count++;
if(count % 5 == 0){
System.out.println();
}
}
i++;
}
}
}
//第二种方法
class While3{
public static void main(String[] args){
int count = 0;
for(int i = 100;i <= 999;i++){
if(i%4==0){
System.out.print(i+"\t");
count++;
if(count%5==0){
System.out.println();
i++;
}
}
}
}
}
学习本身就是一个遗忘后再复习的循环往复的过程,打好每一步基础才会登上更高的平台。