import java.util.Random; import java.util.Scanner; /** * @author shkstart * @create 2023-10-25 14:50 */ public class kk { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("测试那个他是否爱你"); int score = 0; //记录选项的分数 while (true) { System.out.println("1代表男生,2代表女生"); String sex = scanner.next(); if (sex.equals("1") || sex.equals("2")) { while (true) { String s = (sex.equals("1") ? "男生" : "女生"); System.out.println("现在进入对" + s + "的问答环节"); System.out.println("他平常会在乎你的感受吗"); System.out.println("A.时刻在意,一感觉到你的情绪不对就会改正"); System.out.println("B.比较在意,他感觉到了不会立刻改正"); System.out.println("C.不在意,他可不会因为你情绪的改变而让他改变"); String option1 = scanner.next(); if (option1.equals("A") || option1.equals("B") || option1.equals("C")) { if (option1.equals("A")) { score += 100; } else if (option1.equals("B")) score += 60; else score += 40; String spouse = sex.equals("1") ? "女生" : "男生"; if (score == 100) System.out.println("那个" + spouse + "对你太好了"); if (score == 60) System.out.println("那个" + spouse + "可能不是很爱你呀"); if (score == 40) System.out.println("趁早放弃那个" + spouse + "吧,他不爱你你该释怀了"); System.out.println("接下来测试一下你们的姻缘"); System.out.println("请输入你的名字"); String name1 = scanner.next(); System.out.println("请输入他的名字"); String name2 = scanner.next(); Random random=new Random(); int yuanfen = random.nextInt(100); System.out.println("你们的缘分值为"+yuanfen+"%"); int yinyuan=(yuanfen+score)/2; System.out.println("你们的姻缘值为"+yinyuan); if(yinyuan<50) System.out.println("经过测算你们真的不适合在一起"); else if(yinyuan<70) System.out.println("经过测算你们还可以处一处"); else System.out.println("经过测算你们真的很相爱,祝福呀"); break; } else { try { throw new MyException("输入错误,请重新输入"); } catch (MyException e) { System.out.println(e.getMessage()); } } } break; } else { try { throw new MyException("输入错误,请重新输入"); } catch (MyException e) { System.out.println(e.getMessage()); } } } } }
异常类
/** * @author shkstart * @create 2023-10-26 11:26 */ public class MyException extends NumberFormatException{ private static final long serialVersionUID = 5162710183389025692L;//随机写一个UID号 public MyException() { super(); } public MyException(String s) { super(s); } }