読者です 読者をやめる 読者になる 読者になる

落書きノート

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

Javaで問題を解く

import java.util.Scanner;

class q4_20 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int retry = 1;
        int num = 0;
        do {
            System.out.print("何月ですか : ");
            num = scan.nextInt();
            if(num < 1 || num > 12) {
                continue;
            }
            switch(num) {
            case 12:
            case 1:
            case 2:
                System.out.println("それは冬です。");
                break;
            case 3:
            case 4:
            case 5:
                System.out.println("それは春です。");
                break;
            case 6:
            case 7:
            case 8:
                System.out.println("それは夏です。");
                break;
            case 9:
            case 10:
            case 11:
                System.out.println("それは秋です。");
                break;
            }

            System.out.print("もう一度?<1...Yes> <0...No> : ");
            retry = scan.nextInt();
        } while(retry == 1);
    }
}



import java.util.Scanner;

class q4_21 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("段数は : ");
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}



import java.util.Scanner;

class q4_22 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("段数は : ");
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            for(int j = 0; j < i + 1; j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}



import java.util.Scanner;

class q4_22_2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("段数は : ");
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            for(int j = i; j < n; j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}




import java.util.Scanner;

class q4_22_3 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("段数は : ");
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            for(int j = i; j < n - 1; j++){
                System.out.print(" ");
            }
            for(int k = 0; k < i + 1; k++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}




import java.util.Scanner;

class q4_22_4 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("段数は : ");
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            for(int j = n - i; j < n; j++){
                System.out.print(" ");
            }
            for(int k = i; k < n; k++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}




import java.util.Scanner;

class q4_22_4_another {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("段数は : ");
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            for(int j = 0; j < i; j++){
                System.out.print(" ");
            }
            for(int k = 0; k < n - i; k++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}