java唐诗测试

package day1121;

import java.util.Random;
import java.util.Scanner;

//创建类
    public class Example {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("唐诗测试游戏:");
        String str = "白日依山尽 黄河入海流 欲穷千里目 更上一层楼 ";
        //创建随机类
        Random r = new Random();
        //第一个字下标
        int ran1 = r.nextInt(5);
        int ran2 = r.nextInt(5) + 6;
        int ran3 = r.nextInt(5) + 12;
        int ran4 = r.nextInt(5) + 18;
        
        char cha1 = str.charAt(ran1);
        char cha2 = str.charAt(ran2);
        char cha3 = str.charAt(ran3);
        char cha4 = str.charAt(ran4);
        
        String tmStr = str.replace(cha1, '_')
                .replace(cha2, '_')
                .replace(cha3, '_')
                .replace(cha4, '_');
        System.out.println(tmStr);

        System.out.print("A、" + cha1+cha2+cha3+cha4);

        System.out.print("     B、" + cha4+cha2+cha3+cha1);

        System.out.print("     C、" + cha1+cha4+cha2+cha4);

        System.out.println("     D、" + cha3+cha2+cha1+cha4);


        while (true){
            System.out.println("请输入你的选项:");
            String item=sc.next();

            if (item.equals("A")){
                System.out.println("对");
                break;
            }else {
                System.out.println("错");

            }
        }
    }


}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值