Main
package edu.xcdq;
public class Main {
public static void main(String[] args) {
//while 循环
/*
i 是循环控制条件 (循环不变量)
i所表示的是循环次数,意义上不能发生改变,所以被称为循环不变量,值可以改变,目的为了维持变量的意义
*/
int i=1 ;
while (i <=100){
System.out.println("第"+ i + "次"+ "好好学习,天天向上");
i =i+1;
}
}
}
demo01
import java.util.Scanner;
/**
* @qvthor liuwenzheng
* @date 2021/3/17 8:20
*/
public class demo01 {
public static void main(String[] args) {
//检查学习情况,直到合格为止
System.out.println("学习合格了吗? (y/n)");
Scanner scanner = new Scanner(System.in);
String hege = scanner.next();
while ("n".equals(hege)){ // (equals 比较字符串中所包含的内容是否相同) 等于 (== 比较两个变量本身的值,即两个对象在内存中的首地址)
System.out.println("上午学习理论");
System.out.println("下午学习编程");
System.out.println("经过复习,这次合格;了吗");
hege =scanner.next();
}
System.out.println("恭喜你合格了,玩去吧");
}
}
demo02
/**
* @qvthor liuwenzheng
* @date 2021/3/17 9:03
*/
public class demo02 {
public static void main(String[] args) {
int year = 2012;
double stud= 250000;
while (stud <=1000000){
stud = stud*(1+0.25); //比较上一年增长 25%
year++;// 有一年
System.out.println(year +"学生数量" + stud);
}
}
}
demo03
import java.util.Scanner;
/**
* @qvthor liuwenzheng
* @date 2021/3/17 9:32
*/
public class demo03 {
public static void main(String[] args) {
String hege = ""; //定义一个全局变量,供下文使用
Scanner scanner = new Scanner(System.in); //把扫描器定义在循环外面,只定义一次,提高程序性能,减少电脑系统资源占用
do {
System.out.println("上级编写程序");
System.out.println("合格了吗");
hege = scanner.next();
}while (!"y".equals(hege));
System.out.println("合格了");
}
}
demo04
import java.util.Scanner;
/**
* @qvthor liuwenzheng
* @date 2021/3/17 10:03
*/
public class demo04 {
public static void main(String[] args) {
Scanner scanner = new Scanner( System.in);
double she = 0 ;
double hua = 0 ;
int tiao = 1 ;
do {
System.out.println("摄氏温度"+ "\t\t" +"华氏温度");
she = she + 20;
hua = she*9/5.0+32;
System.out.println(she + "\t\t" + hua);
tiao ++;
}while (tiao <=10 );
}
}
demo05
/**
* @qvthor liuwenzheng
* @date 2021/3/17 10:30
*/
public class demo05 {
public static void main(String[] args) {
double she = 0 ;
double hua = 0 ;
int tiao = 1;
while (tiao <=10){
she = she + 20;
hua = she *9 /5.0 + 32 ;
tiao++;
System.out.println("摄氏温度" +"\t\t" + "华氏温度");
System.out.println(she + "\t\t" + hua);
}
}
}
demo06
package edu.xcdq;
import java.util.Scanner;
/**
* @qvthor liuwenzheng
* @date 2021/3/17 10:42
*/
public class demo06 {
public static void main(String[] args) {
System.out.println("欢迎使用商店管理系统");
System.out.println("*****************************************");
System.out.println("1 客户信息管理");
System.out.println("2 购物结算");
System.out.println("3 真情回馈");
System.out.println("4 注销");
System.out.println("*****************************************");
System.out.println("请选择,输入数字:");
Scanner scanner = new Scanner(System.in);
int funno = scanner.nextInt();
do {
if (funno ==1 || funno ==2|| funno ==3 ||funno==4){
switch (funno) {
case 1:
System.out.println("客户信息管理");
scanner.next();
break;
case 2:
System.out.println("购物结算");
scanner.next();
break;
case 3:
System.out.println("真情回馈");
scanner.next();
break;
case 4:
System.out.println("注销");
scanner.next();
break;
}
}else{
System.out.println("输入错误,请重新输入");
funno = scanner.nextInt();
}
}while ( true); //执行成功过一次 !(funno ==1 || funno ==2|| funno ==3 ||funno==4)
}
}
demo07
package edu.xcdq;
/**
* @qvthor liuwenzheng
* @date 2021/3/17 11:06
*/
public class demo07 {
public static void main(String[] args) {
int num = 0;
int sum= 0;
while (num< 100){
num = num+2;
sum = sum +num ;
System.out.println(sum);
}
System.out.println(sum);
}
}