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("错"); } } } }
java唐诗测试
最新推荐文章于 2024-09-05 10:39:00 发布