public class jh_01_循环学习需要用到的知识点 {
public static void main(String[] args) {
int a = 1;// 把数值1赋值给int类型的a a ++;// 对自身加1;
System.out.println(a);
a --;
System.out.println(a); // a <= 10 --- 成立. true
System.out.println(a <= 10); // 字符串比较内容相等.
String str = "xiaojiejie"; String answer = "n";
boolean result = "y".equals(answer);
System.out.println("y".equals(answer)); // nextInt(); // if() {
//
// }else { }
}

  

public class jh_02_为什么需要循环2_1 {
public static void main(String[] args) {
System.out.println("xiaojiejie");
System.out.println("xiaojiejie");
System.out.println("xiaojiejie");
System.out.println("xiaojiejie");
System.out.println("xiaojiejie");
/*
* int i = 1
* 循环条件:-- 不到100遍。-- i <= 100
* 循环操作 :print();
* 1 :有要重复的事。
* System.out.println("xiaojiejie");
*
* 2:重复的条件。什么时候重复,什么时候不重复。
*
* 3:想办法 去。影响条件。
*/ } }

  

public class jh_03_什么是while循环 {
public static void main(String[] args) {
// if (condition) {
//
// }
// while (condition) {
//
// }
// while (条件) {
// // 重复干的事。
// }
//
// while (循环条件) {
// // 循环操作---循环体。
// }
//
// while (不到100遍) {
// // print()。
// }
int i = 1;
while (i<=100) {
// print()。
System.out.println("xiaojiejie");
i ++;
} } }

  

public class jh_04_输出100遍helloworld {
public static void main(String[] args) {
// int i = 1;
// while (i<=100) {
// // print()。
// System.out.println("helloworld");
// i ++;
int i = 1;
while (i<=100) {
// print()。
System.out.println("helloworld");
i ++; }
} }

  

import java.util.Scanner;

public class jh_05_使用while循环4_3 {
/*
* 老师每天检查张浩的学习任务是否合格,
* 如果不合格,则继续进行。
* 老师给张浩安排的每天的学习任务为:
* 上午阅读教材,学习理论部分,
* 下午上机编程,掌握代码部分。
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
/*
* while(){
* }
*/
String answer = "n";
while ("n".equals(answer)) {
System.out.println("上午");
System.out.println("下午");
System.out.println("是否合格?");
answer = sc.next();
}
System.out.println("合格了");
} }

  

public class jh_06_while循环_现场编程 {
/*
* 2012年培养学员25万人,
* 每年增长25%,请问按此增长速度,
* 到哪一年培训学员人数将达到100万人?
*/
public static void main(String[] args) {
/*
* 1: 循环操作. num * (1 + 0.25) 年份加1
* 2: 循环条件. num <= 100;
* -- 套用while循环语法结构
*/
int year = 2012;
int num = 25;
while(num <= 100) {
// num = (int) (num * (1+0.25));
num *= (1 + 0.25);
year ++;
}
System.out.println(num);
System.out.println(year); } }

  

public class jh_07_计算100以内的偶数之和2_1 {
public static void main(String[] args) {
// 1 -- 10
int i = 1;
int sum = 0;
while(i<=100) {
// System.out.println(i);
if(i % 2 == 0) {
sum += i;
}
i++;
}
System.out.println(sum);
} }

  

import java.util.Scanner;

public class jh_08_学员操作_查询商品价格2_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("**************");
System.out.println("1:A 2:B 3 :C");
System.out.println("**************");
System.out.println("请选择编号:");
int choose = sc.nextInt();
// 根据choosez做判断。
switch (choose) {
case 1:
System.out.println("A");
break;
case 2:
System.out.println("B");
break;
case 3:
System.out.println("C");
break; default:
break;
} System.out.println();
System.out.println("是否继续");
String answer = sc.next();
while("y".equals(answer)) {
System.out.println("请选择编号:");
choose = sc.nextInt();
// 根据choosez做判断。
switch (choose) {
case 1:
System.out.println("A");
break;
case 2:
System.out.println("B");
break;
case 3:
System.out.println("C");
break; default:
break;
}
// 判断以后,改变循环条件
System.out.println("是否继续");
answer = sc.next();
} System.out.println("执行结束"); } }

  

import java.util.Scanner;

public class jh_09_为什么需要do_while循环 {
/*
* 经过几天的学习,老师给张浩一道测试题,
* 让他先上机编写程序完成,
* 然后老师检查是否合格。
* 如果不合格,则继续编写。
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// System.out.println("上机编写程序");
// System.out.println("检查是否合格?y/n");
// String answer = sc.next();
// while("n".equals(answer)) {
// System.out.println("上机编写程序");
// System.out.println("检查是否合格?y/n");
// answer = sc.next();
// }
String answer = "";
do {
System.out.println("上机编写程序");
System.out.println("检查是否合格?y/n");
answer = sc.next();
}while("n".equals(answer)); } }

  

public class jh_10_现场编程do_while {
/*
* 使用do-while实现:
* 输出摄氏温度与华氏温度的对照表,
* 要求它从摄氏温度0度到250度,每隔20度为一项,
* 对照表中的条目不超过10条。
* 转换关系:华氏温度 = 摄氏温度 * 9 / 5.0 + 32
* 1摄氏度=33.8华氏度
*/
public static void main(String[] args) {
int ss = 0;
int count = 0;
do {
// 华氏温度 = 摄氏温度 * 9 / 5.0 + 32
//
double hs = ss * 9 / 5.0 + 32;
System.out.println(ss + " = " + hs );
count ++;
ss += 20;
}while(ss <= 250 && count < 10); } }

  

public class jh_11_比较while和do_while {
public static void main(String[] args) {
/*
*1: 语法不同
*2: 执行次序不同
*3: 初始情况不满足循环条件时
*初始情况不满足循环条件时
*while循环一次都不会执行
*do-while循环不管任何情况都至少执行一次
*/
// while() {}
// do {}while(); int i = 1;
int sum = 0;
do {
if(i % 2 == 0) {
sum += i;
}
i++;
}while(i<=100);
System.out.println(sum); // 输出10次helloworld
// int i = 1;
// do {
// System.out.println("helloworld");
// i ++;
// }while(i<=10); // int i = 1;
// while(i<=10) {
// System.out.println("helloworld");
// i++;
} }

  

import java.util.Scanner;

public class jh_12_学员操作升级购物结算 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 商品名称
String tx = "T恤";
String wqx = "网球鞋";
String wqp = "网球拍"; // 单价
int txPrice = 245;
int wqxPrice = 570;
int wqpPrice = 320;
System.out.println("****************************");
System.out.println();
System.out.println("请选择商品编号:");
System.out.println("1:" + tx + "\t2:" + wqx+"\t3:"+wqp );
System.out.println("*****************************");
System.out.println();
// 声明一个变量表示回答的内容。
String answer = "";
// 声明一个变量用于存储,商品累加额。
int sumMoney = 0;
do {
System.out.println("请输入购买的商品编号:");
int goodsId= sc.nextInt();
System.out.println("请输入购买的数量:");
int goodsCount = sc.nextInt(); // 判断 --- 键值对
switch (goodsId) {
case 1:
System.out.println(tx+ "\t"+txPrice+"\t数量"+goodsCount+
"\t合计: "+(txPrice*goodsCount));
// 把钱累加起来。
sumMoney += txPrice*goodsCount;
break;
case 2:
System.out.println(wqx+ "\t"+wqxPrice+"\t数量"+goodsCount+
"\t 合计:"+(wqxPrice * goodsCount));
sumMoney += wqxPrice * goodsCount;
break;
case 3:
System.out.println(wqp+ "\t"+wqpPrice+"\t数量"+goodsCount+
"\t合计: "+(wqpPrice*goodsCount));
sumMoney += wqpPrice * goodsCount;
break; default:
break;
}
System.out.println("是否继续:y/n");
answer = sc.next();
}while("y".equals(answer));// answer cannot be resolved to a variable // 定义一个变量表示折扣。
double discount = 0.8;
// 定义一个变量表示应付金额:
double payMoney = sumMoney *discount; System.out.println("折扣:"+discount);
System.out.println("应付金额:"+payMoney);
System.out.println("实付金额:");
int pay = sc.nextInt();
System.out.println("找钱:" + (pay-payMoney));
} }

  

import java.util.Scanner;

public class jh_13_学员操作_升级菜单切换 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("**********************************");
System.out.println();
System.out.println("\t1: 客户信息管理");
System.out.println("\t2: 购物结算");
System.out.println("\t3:真情回馈");
System.out.println("\t4: 注销");
System.out.println("**********************************");
int choose = 0;
boolean flag = false;
do {
System.out.println("请选择,输入数字: ");
choose = sc.nextInt();
switch (choose) {
case 1:
System.out.println("客户信息管理");
flag = false;
break;
case 2:
System.out.println("购物结算");
break;
case 3:
System.out.println("真情回馈");
flag = false;
break;
case 4:
System.out.println("注销");
flag = false;
break;
default:
flag = true;
break;
} }while(flag);
System.out.println("程序结束");
}
// do {
// System.out.println("请选择,输入数字: ");
// choose = sc.nextInt();
// switch (choose) {
// case 1:
// System.out.println("客户信息管理");
// break;
// case 2:
// System.out.println("购物结算");
// break;
// case 3:
// System.out.println("真情回馈");
// break;
// case 4:
// System.out.println("注销");
// break;
//
// default:
// break;
// }
//
// }while(choose != 1 && choose != 2 && choose != 3 && choose != 4);
//} }

  

java5循环结构一的更多相关文章

  1. Java 7-Java 循环结构 - for, while 及 do…while

    Java 循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whi ...

  2. java入门---循环结构 - for, while 及 do...while&break&continue

        顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构.Java中有三种主要的循环结构: while 循环 do…while 循环 for 循环     在Jav ...

  3. Java循环结构 - for, while 及 do...while

    Java循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whil ...

  4. Java基础(三)选择和循环结构

    一.选择结构,条件判断 1.if 语句 一个 if 语句包含一个布尔表达式和一条或多条语句.如果布尔表达式的值为 true,则执行 if 语句中的代码块,否则执行 if 语句块后面的代码. impor ...

  5. Java 循环结构

    Java 循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whi ...

  6. Java-Runoob:Java 循环结构

    ylbtech-Java-Runoob:Java 循环结构 - for, while 及 do...while 1.返回顶部 1. Java 循环结构 - for, while 及 do...whil ...

  7. Java 循环结构 - for, while 及 do...while

    Java 循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whi ...

  8. java系统化基础-day02-运算符、选择结构、循环结构

    1.java中的运算符 package com.wfd360.day02; import org.junit.Test; import java.math.BigInteger; /** * 1.算术 ...

  9. Day04:循环结构(while、do-while、for)

    Java 循环结构 - while ,do...while,for 反复执行一段相同或相似代码的格式. 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java ...

随机推荐

  1. xshell连接kali linux虚拟机

    这次测试一波三折 刚开始在百度经验看的先修改ssh参数,蓝色的字是百度的,重点都在图片上 1.修改sshd_config文件,命令为: vi /etc/ssh/sshd_config 将#Passwo ...

  2. 【一起学源码-微服务】Hystrix 源码一:Hystrix基础原理与Demo搭建

    说明 原创不易,如若转载 请标明来源! 欢迎关注本人微信公众号:壹枝花算不算浪漫 更多内容也可查看本人博客:一枝花算不算浪漫 前言 前情回顾 上一个系列文章讲解了Feign的源码,主要是Feign动态 ...

  3. 极简安装 TensorFlow 2.0 GPU

    前言 之前写了几篇关于 TensorFlow 1.x GPU 版本安装的博客,但几乎没怎么学习过.之前基本在搞 Machine Learning 和 Data Mining 方面的东西,极少用到 NN ...

  4. 如何应用threejs实现立方体每个面用图片替换

    var geometry = new THREE.BoxGeometry(200, 200, 200);var materialsbg = []; for (var i = 0; i < geo ...

  5. springboot +fastdfs 上传文件到到云服务器

    fastdfs在云服务器的搭建和配置:https://blog.csdn.net/qq_41592652/article/details/104006289 springboot结构如下: appli ...

  6. Unity事件系统EventSystem简析

    相关组件和类 EventSystem 1.负责InputModule的切换(因为现在游戏大部分都只有一个StanaloneInputModule,所以切换这部分可以先不考虑). 2.负责InputMo ...

  7. playbooks框架部署远程主机

    进入到ansible和python环境 进入python3.6虚拟环境 #su - deploy #source .py3-a2.5-env/bin/activate 加载ansible 2.5版本 ...

  8. java 赋值运算

    注意:在赋值运算的时候,会自动发生数据类型转变 例子 public class test{ public static void main(String[] args){ byte num = 5; ...

  9. python 打印乘法表

    for i in range(1, 10): for j in range(1, i+1): print('%s * %s = %s' % (i, j, i*j), end=' ') print('' ...

  10. 洛谷P3645 [APIO2015]雅加达的摩天楼

    题目描述 印尼首都雅加达市有 N 座摩天楼,它们排列成一条直线,我们从左到右依次将它们编号为 0 到 N − 1.除了这 NN 座摩天楼外,雅加达市没有其他摩天楼. 有 M 只叫做 “doge” 的神 ...