Untitled

package chapter02;

import java.util.Scanner;

public class Exercise21 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		System.out.print("가로의 길이는?(단위: m): ");
//		String width = scanner.nextLine();
//		double w = Double.parseDouble(width);
		double width = scanner.nextDouble();
		System.out.print("세로의 길이는?(단위: m): ");
//		String height = scanner.nextLine();
//		double h = Double.parseDouble(height);
		double height = scanner.nextDouble();
		
		System.out.println("직사각형의 넓이: " + (width * height));
		System.out.println("직사각형의 둘레: " + ((width * 2) + (height * 2)) );
	

Untitled

package chapter02;

public class Exercise22 {

	public static void main(String[] args) {
		double distance = 40e12;
		int speed = 300000;
		
		System.out.println("빛의 속도로 프록시마 센타우리 별까지 가는데 걸리는 시간은 " + (distance/speed)/60/60/24/365 + "광년이다.");

	}

}

Untitled

package chapter02;

import java.util.Scanner;

public class Exercise24 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		System.out.print("원기둥 밑변의 반지름을 입력하시오.(단위: cm): ");
		double harf = scanner.nextDouble();
		
		System.out.print("원기둥 높이를 입력하시오.(단위: cm): ");
		double high = scanner.nextDouble();
		
		double area = (harf * harf * Math.PI );
		
		System.out.printf("원기둥 밑변의 넓이는 %.13fcm^2이고, 원기둥의 부피는 %.13fcm^3이다. ", area
				, (area * high));

	}

}

Untitled

package chapter02;

import java.util.Scanner;

public class Exercise25 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		System.out.print("500원짜리 동전의 갯수: ");
		int c500 = scanner.nextInt();
		
		System.out.print("100원짜리 동전의 갯수: ");
		int c100 = scanner.nextInt();
		
		System.out.print("50원짜리 동전의 갯수: ");
		int c50 = scanner.nextInt();
		
		System.out.print("10원짜리 동전의 갯수: ");
		int c10 = scanner.nextInt();
		
		int total = ((500 * c500) + (100 * c100) + (50 * c50) + (10 * c10));
		System.out.println("저금통 안의 동전의 총 액수: " + total);

	}

}