落書きノート

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

Javaで問題を解く

import java.util.Scanner;

class q5_3 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("x : ");
        float x = scan.nextFloat();
        System.out.print("y : ");
        double y = scan.nextDouble();
        System.out.println("x : " + x);
        System.out.println("y : " + y);
    }
}



class q5_4 {
    public static void main(String[] args) {
        boolean b1 = true;
        boolean b2 = false;
        System.out.println("b1 = " + b1);
        System.out.println("b2 = " + b2);
    }
}




import java.util.Scanner;

class q5_5 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("xの値 : ");
        int x = scan.nextInt();
        System.out.print("yの値 : ");
        int y = scan.nextInt();
        System.out.print("zの値 : ");
        int z = scan.nextInt();
        int sum = x + y + z;
        double ave = sum / 3;
        System.out.println("合計は" + sum + "です。");
        System.out.printf("平均は%.3fです。\n", ave);
    }
}




import java.util.Scanner;

class q5_6 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("xの値 : ");
        int x = scan.nextInt();
        System.out.print("yの値 : ");
        int y = scan.nextInt();
        System.out.print("zの値 : ");
        int z = scan.nextInt();
        int sum = x + y + z;
        double ave = (double)sum / 3;
        System.out.println("合計は" + sum + "です。");
        System.out.printf("平均は%.3fです。\n", ave);
    }
}




class q5_7 {
    public static void main(String[] args) {
        int a = (int)10.0;
        System.out.println("a = " + a);
    }
}




class q5_8 {
    public static void main(String[] args) {
        System.out.printf("float\t\tint\n");
        System.out.println("-----------------------------");
        float x = 0.0f;
        for(int i = 0; i <= 1000; i++, x += 0.001f) {
            System.out.printf("%9.7f\t%9.7f\n", x, (float)i / 1000);
        }
    }
}




class q5_9 {
    public static void main(String[] args) {
        System.out.printf("x\t\txの2乗\n");
        System.out.println("----------------------------");
        for(float i = 0.0f; i <= 1.0f; i += 0.001f)
            System.out.printf("%5.3f\t%10.7f\n", i, i * i);
    }
}




class q5_10 {
    public static void main(String[] args) {
        System.out.println("\"ABC\\n\"");
    }
}