goblin
리니팅
goblin

공지사항

전체 방문자
오늘
어제
  • 분류 전체보기 (75)
    • 개발 (31)
      • Spring (12)
      • JPA (4)
      • JAVA (4)
      • Python (6)
      • Docker (1)
      • Error (3)
      • Spring Cloud로 개발하는 MSA (1)
    • 알고리즘 (32)
    • 자료구조 (3)
    • 컴퓨터 개론 (3)
    • 개인 프로젝트 (4)
      • 쇼핑몰 만들기 (4)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

인기 글

태그

  • BOJ
  • 클래스
  • 프로그래머스
  • 객체
  • 알고리즘
  • 스프링부트
  • Intellij
  • 코딩테스트연습
  • 문자열
  • tdd
  • Spring
  • 조합
  • 다이나믹 프로그래밍
  • gradle
  • python
  • 스프링
  • 파워자바
  • sorting
  • 동적계획법
  • 백준
  • inflearn
  • 정렬
  • 자료구조
  • 코딩테스트
  • 다이나믹프로그래밍
  • dp
  • 파이썬
  • 구현
  • springboot
  • JPA

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
goblin

리니팅

개발/JAVA

명품 자바 에센셜 2장 실습 문제

2022. 4. 3. 21:59
728x90

1번

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("두 정수를 입력하세요>>");

		int a,b;
		a = sc.nextInt();
		b = sc.nextInt();

		System.out.println(a+ "+" +b +"은 "+(a+b));
	}

}

 

2번

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("몇 층인지 입력하세요>>");

		int a;
		a = sc.nextInt();

		System.out.println(a*5+"m 입니다.");
	}

}

 

3번

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("x 값을 입력하세요>>");

		int x,y;
		x = sc.nextInt();
		y=x*x-3*x+7;
		

		System.out.println("x="+x+", y="+y);
	}

}

 

4번

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("점 (x,y)의 좌표를 입력하세요>>");

		int x,y;
		x = sc.nextInt();
		y = sc.nextInt();
		
		if(x>=50 && x<=100) {
			if(y>=50 && y<=100) {
				System.out.printf("점(%d,%d)은 (50,50)과 (100,100)의 사각형 내에 있습니다.",x,y);
			}else {
				System.out.printf("점(%d,%d)은 (50,50)과 (100,100)의 사각형 내에 있지 않습니다.",x,y);
			}
		}else {
			System.out.printf("점(%d,%d)은 (50,50)과 (100,100)의 사각형 내에 있지 않습니다.",x,y);
		}
	}

}

 

5번

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("논리 연산을 입력하세요>>");
		
		boolean a=sc.nextBoolean();
		String op=sc.next();
		boolean b=sc.nextBoolean();
		
		switch(op) {
			case "AND" : {
				System.out.println(a && b);
				break;
			}
			case "OR" : {
				System.out.println(a || b);
				break;
			}
		}
	}

}

 

6번

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();
		int rest=money;
		
		money/=50000;
		System.out.print("오만원"+money+"개, ");
		money=rest%50000;
		
		money/=10000;
		System.out.print("만원"+money+"개, ");
		money=rest%10000;
		
		money/=1000;
		System.out.print("천원"+money+"개, ");
		money=rest%1000;
		
		money/=500;
		System.out.print("500원"+money+"개, ");
		money=rest%500;
		
		money/=100;
		System.out.print("100원"+money+"개, ");
		money=rest%100;

		money/=10;
		System.out.print("10원"+money+"개, ");
		money=rest%10;

		System.out.print("1원"+money+"개");


		sc.close();
	}

}

 

7번

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		System.out.print("학점을 입력하세요>>");
		String grade =sc.next();
		
		switch(grade) {
		case "A": case "B" :{
			System.out.println("Excellent");
			break;
		}
		case "C": case "D" :{
			System.out.println("Good");
			break;
		}
		case "F":{
			System.out.println("Bye");
			break;
		}
		default:{
			System.out.println("잘못된 입력입니다.");
			break;
		}
		
		}
	}
}

 

8번

(1) if문을 활용하라.

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 문을 활용하라.

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;
			}
		}

	}
}

 

9번

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;
		}
	}
}

 

10번

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("에스프레소")) {
			int sum=2000*quantity;
			if(quantity>=10) {
				sum*=0.95;
				System.out.println(sum+"원입니다.");
			}else {
			System.out.println(sum+"원입니다.");
			}
		}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("잘못된 입력입니다.");
		}
			
	}
}

 

728x90
반응형

'개발 > JAVA' 카테고리의 다른 글

[SpringBoot] lombok  (0) 2022.05.22
POWER JAVA(파워 자바 개정3판) - 5장 클래스와 객체 II Mini Project  (0) 2022.04.10
POWER JAVA(파워 자바 개정 3판) - 4장 클래스와 객체 I Mini Project  (0) 2022.04.10
    '개발/JAVA' 카테고리의 다른 글
    • [SpringBoot] lombok
    • POWER JAVA(파워 자바 개정3판) - 5장 클래스와 객체 II Mini Project
    • POWER JAVA(파워 자바 개정 3판) - 4장 클래스와 객체 I Mini Project
    goblin
    goblin

    티스토리툴바