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

落書きノート

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

Javaで問題を解く

import java.util.Scanner;

class q2_7 {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        System.out.println("整数値を入力してください。");
        int target = scan.nextInt();
        
        System.out.println(target / 10);
        System.out.println(target % 10);
    }
}


import java.util.Scanner;

class q2_8 {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        System.out.println("xの値");
        float x = scan.nextFloat();
        System.out.println("yの値");
        float y = scan.nextFloat();

        System.out.println(x + y);
        System.out.println((x + y) / 2);
    }
}



import java.util.Scanner;

class q2_9 {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        
        System.out.println("底辺の長さ");
        float bottom = scan.nextFloat();
        System.out.println("高さ");
        float height = scan.nextFloat();

        System.out.println("面積は" + bottom * height / 2 + "です。");
    }
}



import java.util.Scanner;

class q2_10 {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        final double PI = 3.14;

        System.out.println("半径を入力してください");
        double r = scan.nextDouble();
        System.out.println("表面積 : " + (4 * PI * r * r));
        System.out.println("体積 : " + (4 / 3.0 * PI * r * r * r));
    }
}



import java.util.Random;

class q2_11 {
    public static void main(String[] args){
        Random rnd = new Random();

        int ran = 1 + rnd.nextInt(9);
        System.out.println(ran);
        ran = -1 + -1 * rnd.nextInt(9);
        System.out.println(ran);
        ran = 10 + rnd.nextInt(90);
        System.out.println(ran);
    }
}