Discuss / Java / 记录一下!

记录一下!

Topic source

綾之桜

#1 Created at ... [Delete] [Delete and Lock User]
import java.util.Scanner;
public class Test {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.print("请输入(1--石头,2--剪刀,3--布):");
		int p = scanner.nextInt();
		int c = 1+ (int)(Math.random()*3);
		switch (p) {
			case 1: {
				System.out.printf("你出的是石头!");
				if (c == 1) {
					System.out.println("电脑出石头!\nDraw!");
				}else if(c == 2) {
					System.out.println("电脑出剪刀!\nYou are win!");
				}else if(c == 3) {
					System.out.println("电脑出布!\nYou are lose!");
				}
			}
				break;
			case 2:{
				System.out.printf("你出的是剪刀!");
				if (c == 1) {
					System.out.println("电脑出石头!\nYou are lose!");
				}else if (c==2) {
					System.out.println("电脑出剪刀!\nDraw!");
				}else if (c==3) {
					System.out.println("电脑出布!\nYou are win!");
				}
			}
				break;
			case 3:{
				System.out.printf("你出的是布!");
				if (c == 1) {
					System.out.println("电脑出石头!\nYou are win!");
				}else if (c==2) {
					System.out.println("电脑出剪刀!\nYou are lose!");
				}else if (c== 3) {
					System.out.println("电脑出布!\nDraw!");
				}
			}
				break;
			default:{
				System.out.printf("错误!请输入1~3以内的數字!");
			}
		}
	}
}

  • 1

Reply