Discuss / Java / 交作业

交作业

Topic source

Tomcat_Cy

#1 Created at ... [Delete] [Delete and Lock User]
public class Main {    public static void main(String[] args) {        System.out.println("选择数字123:");        System.out.println(" 1: 石头");        System.out.println(" 2: 剪刀");        System.out.println(" 3: 布");        Scanner scanner = new Scanner(System.in);        // 用户输入:        int choice = scanner.nextInt();        // 计算机随机数 1, 2, 3:        int random = 1 + (int) (Math.random() * 3);        switch (choice) {            case 1:                System.out.println("你出的是石头");                System.out.println(random==1?"电脑出的是石头!":random==2?"电脑出的是剪刀!":"电脑出的是布!");                System.out.println(random==1?"平局!":random==2?"你赢了!":"你输了!");                break;            case 2:                System.out.println("你出的是剪刀");                System.out.println(random==1?"电脑出的是石头!":random==2?"电脑出的是剪刀!":"电脑出的是布!");                System.out.println(random==2?"平局!":random==3?"你赢了!":"你输了!");                break;            case 3:                System.out.println("你出的是布");                System.out.println(random==1?"电脑出的是石头!":random==2?"电脑出的是剪刀!":"电脑出的是布!");                System.out.println(random==3?"平局!":random==1?"你赢了!":"你输了!");                break;            default:                System.out.println("选择错误!");                break;        }    }}

Tomcat_Cy

#2 Created at ... [Delete] [Delete and Lock User]
public class Main {
  public static void main(String[] args) {
    System.out.println("please choice:");        
    System.out.println(" 1: 石头");        
    System.out.println(" 2: 剪刀");        
    System.out.println(" 3: 布");        
    Scanner scanner = new Scanner(System.in);        
    // 用户输入:        
    int choice = scanner.nextInt();        
    // 计算机随机数 1, 2, 3:        
    int random = 1 + (int) (Math.random() * 3);        
    switch (choice) {
      case 1:
        System.out.println("你出的是石头");                
        System.out.println(random==1?"电脑出的是石头!":random==2?"电脑出的是剪刀!":"电脑出的是布!");                
        System.out.println(random==1?"平局!":random==2?"你赢了!":"你输了!");                
        break;            
      case 2:
        System.out.println("你出的是剪刀");                
        System.out.println(random==1?"电脑出的是石头!":random==2?"电脑出的是剪刀!":"电脑出的是布!");                
        System.out.println(random==2?"平局!":random==3?"你赢了!":"你输了!");                
        break;            
      case 3:
        System.out.println("你出的是布");                
        System.out.println(random==1?"电脑出的是石头!":random==2?"电脑出的是剪刀!":"电脑出的是布!");                
        System.out.println(random==3?"平局!":random==1?"你赢了!":"你输了!");                
        break;            
      default:
        System.out.println("选择错误!");                
        break;        
    }
  }
}


  • 1

Reply