Discuss / Java / 练习题

练习题

Topic source

追风少年

#1 Created at ... [Delete] [Delete and Lock User]
        Scanner scanner = new Scanner(System.in);
		System.out.print("请选择类型:\n1:石头\n2.剪刀\n3.布\n");
		int choice = scanner.nextInt();

		int random = (int)(Math.random() * 3 + 1);

		switch(choice - random) {
			case 0:
				System.out.println("平局");
				break;
			case -1:
			case 2:
				System.out.println("你赢了");
				break;
			case 1:
			case -2:
				System.out.println("你输了");
			default:
				System.out.println("输入非法");
				break;
		}

  • 1

Reply