본문 바로가기
솔루션모음/파워자바 프로그래밍

[파워자바] 5장 프로그래밍 솔루션 답지

by 이얏호이야호 2023. 2. 15.

 

1.

import java.util.Scanner;
public class Test {
    public static void main(String args[]) {
    	String name;
		Scanner sc = new Scanner(System.in);
		System.out.print("이름: ");
		name = sc.next(); // 문자열은 next()로 받는다. 
		System.out.print("나이: ");
		int age = sc.nextInt();
		System.out.print("이름은 "+ name + "이고 나이는 " + age +"입니다.");
	}
}

 

2.

import java.util.Scanner;

public class Test {
    public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		System.out.print("정수를 입력하시오: ");
		int x = sc.nextInt();  
		System.out.print("정수를 입력하시오: ");
		int y = sc.nextInt();
		int max = (x > y)? x:y;
		int min = (x < y)? x:y;
		System.out.println(max + "을" +min+" 으로 나눈 몫은" + max/min + "이고 나머지는" +
				max%min+" 입니다.");
	}
}

 

3.

import java.util.Scanner;

public class Test {
    public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		System.out.print("키를 입력하시오: ");
		int x = sc.nextInt();  
		int feet = (int)(x/30.48);
		System.out.println(x + "는" + feet + "피트" 
				+ (x-30.48*feet)/2.54 + "인치입니다.");
	}
}

 

 

 

 

 

4.

import java.util.Scanner;

public class Test {
    public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		System.out.print("원기둥의 반지름: ");
		double r = sc.nextDouble();  
		System.out.print("원기둥의 높이: ");
		double h = sc.nextDouble();
		double volume = (3.141592*r*r)*h;
		System.out.println("원기둥의 부피는 "+volume);
	}
}

 

5.

import java.util.Scanner;

public class Volume {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		byte a, b, c;
		System.out.println("길이 : ");
		a = (byte) s.nextInt();
		System.out.println("너비 : ");
		b = (byte) s.nextInt();
		System.out.println("높이 : ");
		c = (byte) s.nextInt();
		System.out.println("부피는 " + a * b * c + "입니다.");
	}
}

 

6.

import java.util.Scanner;

public class PiggyBank {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.println("500원 동전 개수 : ");
		int a =  s.nextInt();
		System.out.println("100원 동전 개수 : ");
		int b =  s.nextInt();
		System.out.println("50원 동전 개수 : ");
		int c =  s.nextInt();
		System.out.println("10원 동전 개수 : ");
		int d =  s.nextInt();
		int total = 500*a+100*b+50*c+10*d;
		System.out.println("금액은 " + total + "입니다.");
	}
}

 

7.

import java.util.Scanner;

public class PiggyBank {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		final double sqm_py=3.3058;

		System.out.print("평 : ");
		double py =  s.nextDouble();
		double sqm =py*sqm_py; 
		System.out.println(sqm);
	}
}

 

8.

public class Distance {
	public static void main(String[] args){
		double d = 1.5e8;
		double s = 3.0e5;
		System.out.println("빛이 지구에 도착하는 시간은 " + d/s + "초 입니다.");
	}
}

 

9.

import java.util.*;
public class Pressure {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		double p, s;
		System.out.print("압력를 입력하세요 : ");
		p = scan.nextDouble();
		System.out.print("면적을 입력하세요 : ");
		s = scan.nextDouble();
		System.out.println(p/s);		
	}
}

 

10.

import java.util.*;
public class Thaies {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		double ac, ae, bc, de;
		System.out.print("AC: ");
		ac = scan.nextDouble();
		System.out.print("AE: ");
		ae = scan.nextDouble();
		System.out.print("BC: ");
		bc = scan.nextDouble();
		System.out.print("DE: ");
		de = scan.nextDouble();
		System.out.println(ae*bc/ac);		
	}
}

댓글