import java.util.Scanner;
//나이를 입력받아 20대인지 판별하는 프로그램을 만들어라 if else사용(1~99)
public class Jogun {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("나이를 입력하세요");
int age = scanner.nextInt();
if((30>age)&&(age>19)) {
System.out.println("20대 입니다.");
} else {
System.out.println("20대가 아닙니다.");
}
scanner.close();
}
}
import java.util.Scanner;
public class If_else {
public static void main(String[] args) {
// 다중 if else를 사용하여 성적을 산출하세요.
Scanner scanner = new Scanner(System.in);
System.out.println("성적을 입력하세요");
int score = scanner.nextInt();
if(score>=90) {
if(score>=95) {
System.out.println("A+");
} else {
System.out.println("A");
}
}
else if(score>=80) {
if(score>=85) {
System.out.println("B+");
} else {
System.out.println("B");
}
}
else if(score>=70) {
if(score>=75) {
System.out.println("c+");
} else {
System.out.println("c");
}
}
else if(score>=60) {
if(score>=65) {
System.out.println("d+");
} else {
System.out.println("d");
}
} else {
System.out.println("f");
}
}
}
import java.util.Scanner;
public class P88_6 {
public static void main(String[] args) {
System.out.println("돈을 입력하세요");
Scanner scanner = new Scanner(System.in);
int money = scanner.nextInt();
System.out.println("오만원권 "+money/50000+"개 ");
money = money%50000;
System.out.println("만원 권 "+money/10000+"개 ");
money = money%10000;
System.out.println("천원 권 "+money/1000+"개 ");
money = money%1000;
System.out.println("오백원 "+money/500+"개 ");
money = money%500;
System.out.println("백원 "+money/100+"개");
money = money%100;
System.out.println("십원 "+money/10+"개");
money= money%10;
System.out.println("일원 "+money/1+"개");
money = money%1;
}
}
import java.util.Scanner;
public class P88_7 {
public static void main(String[] args) {
System.out.println("성적을 입력하세요");
Scanner scanner = new Scanner(System.in);
char score = scanner.next().charAt(0);
switch(score) {
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("다시입력해주세요");
}
}
}
import java.util.Scanner;
public class P88_8 {
public static void main(String[] args) {
System.out.println("커피를 주문하세요");
Scanner scanner = new Scanner(System.in);
String menu = scanner.next();
int num = scanner.nextInt();
if(menu.equals("에스프레소")) {
int price = num * 2000;
System.out.println(price+"원입니다");
}
else if(menu.equals("아메리카노")) {
int price = num *2500;
System.out.println(price+"원입니다");
}
else if(menu.equals("카푸치노")) {
int price = num *3000;
System.out.println(price+"원입니다");
}
else if(menu.equals("카페라테")) {
int price = num *3500;
System.out.println(price+"원입니다");
}
scanner.close();
}
}
import java.util.Scanner;
public class P88_8switch {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("커피 주문하세요");
String coffee = scanner.next();
int num = scanner.nextInt();
switch(coffee) {
case "아메리카노":
int price = num * 2500;
System.out.println(price+"원입니다");
break;
case "카푸치노":
price = num * 3000;
System.out.println(price+"원입니다");
break;
case "에스프레소":
price = num * 2000;
System.out.println(price+"원입니다");
break;
case "카페라테":
price = num * 3500;
System.out.println(price+"원입니다");
break;
default:
System.out.println("다시 입력해주세요");
}
}
}
import java.util.Scanner;
public class P88_9 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("1~99정수를 입력하세요");
int num = scanner.nextInt();
int first = num/10;
int second = num%10;
if(first%3==0){
if(second%3==0) {
System.out.println("박수짝짝");
}else {
System.out.println("박수짝");
}
}
else if (second%3==0) {
System.out.println("박수짝");
} else {
System.out.println("박수없음");
}
scanner.close();
}
}
import java.util.Scanner;
public class P88_10 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("커피 주문하세요");
String coffee=scanner.next();
int num = scanner.nextInt();
if(coffee.equals("에스프레소")) {
if(num>=10){
int price=num*1900;
System.out.println(price+"입니다.");
} else {
int price = num * 2000;
System.out.println(price+"입니다.");
}
}
else if(coffee.equals("아메리카노")) {
int price = num * 2500;
System.out.println(price+"입니다.");
}
else if(coffee.equals("카푸치노")) {
int price = num * 3000;
System.out.println(price+"입니다.");
}
else if(coffee.equals("카페라테")) {
int price = num * 3500;
System.out.println(price+"입니다.");
}
scanner.close();
}
}
package ch03;
//while문을 사용하여 1~10까지 화면에 출력하는 프로그램 작성하세요
public class While1 {
public static void main(String[] args) {
int num=1;
while(num<11) {
System.out.print(num);
num++;
}
}
}
// 1부터 10까지의 합
int i = 1;
int sum=0;
while(i<11) {
sum = sum+i;
i++;
}
System.out.println("합계: "+sum);
}