6. 돈의 액수를 입력받아 오만원권, 만원권, 천원권, 500원짜리 동전, 100원짜리 동전, 10원짜리 동전, 1원짜리 동전 각 몇 개로 변환되는지 출력하라.

package blog;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("돈의 액수를 입력하세요>>");

		int money = sc.nextInt();
		
		System.out.print("오만원권"+money/50000+"개, ");
		money %= 50000;
		System.out.print("만원"+money/10000+"개, ");
		money %= 10000;
		System.out.print("천원"+money/1000+"개, ");
		money %= 1000;
		System.out.print("500원"+money/500+"개, ");
		money %= 500;
		System.out.print("100원"+money/100+"개, ");
		money %= 100;
		System.out.print("10원"+money/10+"개, ");
		money %= 10;
		System.out.println("1원"+money+"개");
	}	
}


8. 음료수 종류와 잔 수를 입력받으면 가격을 알려주는 프로그램을 작성하라. 에스프레소는 2000원, 아메리카노 2500원, 카푸치노 3000원, 카페라떼 3500원이다.

(1) if문을 활용하라.

package blog;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("커피를 주문하세요>>");

		String coffee = sc.next();
		int Quantity = sc.nextInt();

		if(coffee.equals("에스프레소"))
			System.out.println(2000*Quantity+"원입니다.");
		else if(coffee.equals("아메리카노"))
			System.out.println(2500*Quantity+"원입니다.");
		else if(coffee.equals("카푸치노"))
			System.out.println(3000*Quantity+"원입니다.");
		else if(coffee.equals("카페라떼"))
			System.out.println(3500*Quantity+"원입니다.");
		else
			System.out.println("잘못 입력하엿습니다.");

	}
}

 

(2) switch문을 활용하라.

package blog;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("커피를 주문하세요>>");

		String coffee = sc.next();
		int Quantity = sc.nextInt();
		
		switch (coffee) {
		case "에스프레소":
			System.out.println(2000*Quantity+"원입니다.");
			break;
		case "아메리카노": 
			System.out.println(2500*Quantity+"원입니다.");
			break;
		case "카푸치노": 
			System.out.println(3000*Quantity+"원입니다.");
			break;
		case "카페라떼": 
			System.out.println(3500*Quantity+"원입니다.");
			break;
		default:
			System.out.println("잘못 입력하엿습니다.");
			break;
		}
	}	
}

9. 369게임의 일부를 작성해보자. 1~99까지의 정수를 입력받고, 수에 3, 6, 9중 하나가 있는 경우는 "박수짝", 두 개 있는 경우는 "박수짝짝", 하나도 없으면 "박수없음"을 출력하는 프로그램을 잣성하라. 예를 들면, 13인 경우 "박수짝", 36인 경우 "박수짝짝", 5인 경우 "박수없음"을 출력하면 된다.

package blog;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("1~99 사이의 정수를 입력하세요>>");

		int num = sc.nextInt();
		
		int first = num/10;
		int second = num%10;
		int cnt = 0;
		
		if(first == 3 || first == 6 || first == 9) cnt++;
		if(second == 3 || second == 6 || second == 9) cnt++;
		
		switch (cnt) {
		case 0: System.out.println("박수없음"); break;
		case 1: System.out.println("박수짝"); break;
		case 2: System.out.println("박수짝짝"); break;
		default:
			break;
		}
	}
}


Bonus 1. 사칙 연산을 입력받아 실행해주는 프로그램을 작성하고자 한다. 이때 연산자는 +, -, *, /의 4가지로 하고 피연산자는 모두 실수이며, 다음과 같이 피연산자와 연산자는 빈칸으로 분리하여 입력하는 것으로 한다. 

package blog;
import java.util.Scanner;
public class Arithmetic {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("식을 입력하세요>>");

		double op1 = sc.nextDouble();
		String operator = sc.next();
		double op2 = sc.nextDouble();
		double result = 0;
        
		switch(operator) {
		case "+" : result = op1 + op2; break;
		case "-" : result = op1 - op2; break;
		case "*" : result = op1 * op2; break;
		case "/" : 
			if(op2 == 0) {
				System.out.println("0으로 나눌 수 없습니다.");
				return;
			}
			result = op1 / op2; break;
		default : System.out.println("연산 기호가 잘못되었습니다.");
		}
		System.out.println(result);
	}	
}