日常作业2018.12.28

作业

1、赌博游戏

 

package com.job12_1;

import java.util.Scanner;
/**
 *  赌博游戏
 * @author Administrator
 *    2018.12.26
 */
public class Gamble {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("**********   赌博游戏您是否参\ty/n\t**********"); String begin=sc.next(); //接收玩家是否开始游戏 if(!"n".equals(begin)) { //选择是否开始游戏 System.out.println("欢迎您的参加,您有多少资金"); int money=sc.nextInt(); //玩家带了多少钱 while(money>5) { //如果小于5块钱游戏结束 int a=(int)(Math.random()*5+1); //第一个骰子点数 int b=(int)(Math.random()*5+1); //第二个骰子点数 int c=(int)(Math.random()*5+1); //第三个骰子点数 String result=a+b+c<=9?"小":"大"; //判断结果大小 System.out.println("请支付下注押金"); int pay=sc.nextInt(); //接收玩家押金金额 System.out.println("请押大押小"); String play=sc.next(); //接收玩家的押注大小 if(play.equals(result)) { //如果玩家大小和骰子大小一样 System.out.println("恭喜你猜对了!"+a+","+b+","+c+result); money+=pay; //本金加上押金 System.out.println("你的本金还有"+money); }else if(!play.equals(result)){ //如果玩家大小和骰子大小不一样 System.out.println("很可以猜错了!"+a+","+b+","+c+result); money-=pay; //本金减上押金 System.out.println("你的本金还有"+money); } } }else { System.out.println("您走好!"); } } }

运行结果

2、一周学习复习休息的安排

 

package com.job12_1;
import java.util.*;
/**
 *     一周计划
 * @author ZZH    
 *    2018.12.26
 */
public class Study {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入今天星期几");
        int week=sc.nextInt();
        switch (week) {
            case 1:
            case 3:
            case 5:
                System.out.println("今天学习");
                break;
            case 2:
            case 4:
            case 6:
                System.out.println("今天复习");
                break;
            case 7:
                System.out.println("今天休息");
        }
    }
}

 

运行结果

 

3、假如你准备去海南旅游现在要订购机票。机票的价格受季节旺季、淡季影响,而且头等舱和经济舱价格也不同。假设机票原件为5000元,4到10月为旺季,旺季头等舱打8折,经济舱打6折,其他月份为淡季,淡季头等舱打5折,经济舱打4折。请编写程序。

 

package com.job12_1;

import java.util.Scanner;
/**
 * 海南旅游机票票价系统
 * @author ZZH
 *    2018.12.26
 */
public class Plane {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int ticket=5000; System.out.println("请输入您出行的月份:1~12"); int month=sc.nextInt(); //接收月份 System.out.println("请问您选择头等舱还是经济舱?1、头等舱\t2、经济舱"); int choose=sc.nextInt(); //接收舱位 double price=0; //赋值票价 if(choose==1) { //如果是头等舱 if(month>=4&&month<=10) { //如果是4到10月 price=ticket*0.9; //票价打九折 }else if(!(month>=4)&&!(month<=10)){ //如果不是4到10月 price=ticket*0.5; //票价打五折  } }else if(choose==2) { //如果是经济舱 if(month>=4&&month<=10) { //如果是4到10月 price=ticket*0.6; //票价打六折 }else if(!(month>=4)&&!(month<=10)){ //如果不是4到10月 price=ticket*0.4; //票价打四折  } } System.out.println("您的机票价格为:"+price); //输出票价  } }

运行结果

 

     

 

作业链接

链接:https://pan.baidu.com/s/1un63b07D1JnKBBZQRbqGmg
提取码:kwtv

 

预习题:
1、有几种循环的语法
while、do-while、for、多重循环


2、几种循环有什么特点
while:while语句是先判断循环条件再执行循环体,如果第一次判断循环条件为假,循环一次也不执行。
do-while:do-while语句先执行循环体再判断循环条件,所以循环体至少执行一次,这一次和while循环正好相反。
for:无论循环多少次,表达式一只执行一次。for语句和while语句功能相似,都是判断条件再执行,只是采取了不同的语法格式。
多重循环:外面的循环称为外层循环,在循环里的循环称为内层循环,外层循环没循环一次,内层循环就完整的执行一遍


3、 循环的几个要素

初始部分:设置循环的初始状态
循环体:重复执行的代码
循环条件:判断是否继续循环的条件

 

转载于:https://www.cnblogs.com/zzh630/p/10181780.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值