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. JWT实现授权认证

    目录 一. JWT是什么 二. JWT标准规范 三. 核心代码简析 四. 登录授权示例 五. JWT 使用方式 六. JWT注意事项 一. JWT是什么 JSON Web Token(JWT)是目前最 ...

  2. Ant Design中根据用户交互展示不同的标签

    Ant Design中根据用户交互展示不同的标签 Ant Design使用的是React框架,那么我们先看代码: <Fragment> <a onClick={() => th ...

  3. JVM系列六(自定义插入式注解器).

    一.概述 从前面 文章 中我们可以了解到,javac 的三个步骤中,程序员唯一能干预的就是注解处理器部分,注解处理器类似于编译器的插件,在这些插件里面,可以读取.修改.添加抽象语法树中的任意元素.因此 ...

  4. Arrays.sort() VS Arrays.parallelSort()

    英文原文地址:Arrays.sort vs Arrays.parallelSort 作者:baeldung 翻译:高行行 1. 概述 我们都使用过 Arrays.sort() 对对象或原始数据类型数组 ...

  5. 悄摸直播(一)—— 推流器的实现(获取笔记本摄像头画面,转流推流到rtmp服务器)

    悄摸直播 -- JavaCV实现本机摄像头画面远程直播 推流器 一.功能说明 获取pc端的摄像头流数据 + 展示直播效果 + 推流到rtmp服务器 二.代码实现 /** * 推流器 * @param ...

  6. a标签点击触发 layer open 只显示背景解决

    问题:公司网站突然说有个查看信息的点击不好使了,有时候点击无反应,但是href执行了,有时候弹出只有背景,不显示内容.网上找了a标签的各种方法尝试后,均不能解决. 代码:类似如下,method()方法 ...

  7. cogs 49. 跳马问题 DFS dp

    49. 跳马问题 ★   输入文件:horse.in   输出文件:horse.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 有一只中国象棋中的 “ 马 ” ,在半张 ...

  8. 用户输入- Unity3D游戏开发培训

    用户输入- Unity3D游戏开发培训   作者:Jesai 时间:2018-02-12 14:28:45 用户输入Input 鼠标按键: -方法:GetMouseButton(); -方法:GetM ...

  9. 内置3D对象-Unity3D游戏开发培训

    内置3D对象-Unity3D游戏开发培训 作者:Jesai 2018-02-12 19:21:58 五大面板: -Hierachy:当前场景中的物体 图 1-1 -Project:项目中的所有资源 图 ...

  10. kafka 中 zookeeper 具体是做什么的?

    zookeeper 是 kafka 不可分割的一部分,可见其重要程度,所以我们有必要了解一下 zookeeper 在 kafka 中的具体工作内容. 而且,这也是面试时经常问的. zookeeper ...