落書きノート

ふと自分が気になった事を書いてます

Javaで問題を解く

import java.util.Scanner;

class q3_18 {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    System.out.print("変数a : "); int a = scan.nextInt();
    System.out.print("変数b : "); int b = scan.nextInt();
    if(!(a >= b)) {
      int t = a;
      a = b;
      b = t;
    }
    System.out.println("変数a : " + a);
    System.out.println("変数b : " + b);
  }
}



import java.util.Scanner;

class q3_19 {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    System.out.print("変数a : "); int a = scan.nextInt();
    System.out.print("変数b : "); int b = scan.nextInt();
    System.out.print("変数c : "); int c = scan.nextInt();
    if(a >= b) {
      int t = a;
      a = b;
      b = t;
    }
    if(b >= c) {
      int t = b;
      b = c;
      c = t;
    }
    if(a >= b) {
      int t = a;
      a = b;
      b = t;
    }
    System.out.println("変数a : " + a);
    System.out.println("変数b : " + b);
    System.out.println("変数c : " + c);
  }
}



import java.util.Random;

class q3_20 {
  public static void main(Stirng[] args){
    Random rnd = new Random();
    int ran = rnd.nextInt(3);

    switch(ran) {
    case 0: System.out.println("グー");
    case 1: System.out.println("チョキ");
    case 2: System.out.println("パー");
    }
  }
}