学习自b站韩顺平老师发布的java30天速成-p127、p128
import java.util.Scanner;
public class while_exercise{
public static void main(String[] args) {
System.out.println("输出i个“你好,韩顺平教育”+i");
int i = 1;
System.out.println("while_one began:输出i个“你好,韩顺平教育”+i");
while(i <= 10){
System.out.println("你好,韩顺平教育 " + i);
i++;
}
System.out.println("out of while_one");
System.out.println("while_two began:打印任意两数之间所有的偶数");//分割用
Scanner scanner = new Scanner(System.in);//定义Scanner类对象scanner
System.out.println("请输入m:");
float m = scanner.nextFloat();
System.out.println("请输入n:");
float n = scanner.nextFloat();
//保证m<n
if(m > n){
float a = m;
m = n; n = a;
}
// int m = 40;
// int n = 100;
//先死后活
System.out.println(m + "到" + n +"之间的偶数有:");
while(m <= n){
if(m % 2 == 0){
System.out.print(m + "\t");
}
m++;
}
}
}
输出: