作业

作业1

在这里插入图片描述

作业2

在这里插入图片描述

作业3

package com.company;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner a = new Scanner(System.in);
        int fw = (int) (Math.random() * 100 + 1);
        int money = 50;
        System.out.println("*猜数字游戏\n*规则:初始金额50元,每猜一局10元 猜中奖励30元,每局有6次机会,数字范围0-100!");
        for (; money >= 10; ) {
            money -= 10;
            System.out.println("\n*余额(本局已交10元):" + money);
            System.out.print("*数字范围0-100!");
            fw = (int) (Math.random() * 100 + 1);
            for (int cishu = 0; cishu < 6; ) {
                cishu++;
                boolean pd = a.hasNextInt();
                if (pd) {
                    int cai = a.nextInt();
                    if (cai > 0 && cai < 100) {
                        if (cai == fw) {
                            System.out.println("*恭喜你猜中了!第" + cishu + "次猜中!奖励30元");
                            money += 30;
                            cishu = 6;
                        } else if (cai > fw) {
                            System.out.println("*大了!已用次数:" + cishu);
                        } else {
                            System.out.println("*小了!已用次数:" + cishu);
                        }
                    } else {
                        System.out.println("*请输入0-100!已用次数:" + cishu);
                    }
                } else {
                    System.out.println("*请输入整数!已用次数:" + cishu);
                    String nazou = a.next();
                }
            }
            if (money < 10) {
                System.out.println("*余额不足!游戏结束!");


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值