2번 switch문에서 사용할 수 있는 변수 타입은 int, double이 될 수 있다.
-> switch 문에서 사용할 수 있는 변수 타입은 정수형 int, char, byte, short과 enum 타입
switch 문의 내부에서 정수형 값 또는 특정 문자나 문자열에 대한 비교 연산을 수행하기 때문
String grade = "B";
int score1 = switch (grade) {
case "A" -> 100;
case "B" -> 100 - 20;
default -> 60;
};
int sum = 0;
for(int i = 1; i <= 100; i++) {
if(i%3 == 0)
sum += i;
}
System.out.print(sum);
int one = (int) (Math.random() * 6 + 1);
int two = (int) (Math.random() * 6 + 1);
while(true) {
int result = one+two;
if(result == 5) {
System.out.printf("(%d, %d)\n", one, two);
return; }
else {
System.out.printf("(%d, %d)\n", one, two);
one = (int) (Math.random() * 6 + 1);
two = (int) (Math.random() * 6 + 1);
continue;
}
}
for(int x = 0; x <= 10; x++) {
for(int y= 1; y <= 10; y++) {
if(4 * x + 5 * y == 60) {
System.out.printf("(%d, %d)\n", x, y);
}
}
}
for(int i = 1; i <= 5; i++) {
for(int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
boolean run = true;
while(run) {
System.out.println("-----------------------------------");
System.out.println("1. 예금 | 2. 출금 | 3. 잔고 | 4. 종료");
System.out.println("-----------------------------------");
System.out.println("선택 > ");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
int balance = 0;
switch(choice) {
case 1 -> {
System.out.println("예금액 >");
int diposit = sc.nextInt();
balance += diposit;
}
case 2 -> {
System.out.println("출금액 >");
int withdraw = sc.nextInt();
balance -= withdraw;
}
case 3 -> {
System.out.printf("잔고 > %d\n", balance);
}
case 4 -> {
run = false;
}
}
}
System.out.print("프로그램 종료");