반응형
3번
// 3번
int sum = 0;
for(int i =1;i<=100;i++) {
if(i%3 == 0) {
sum += i;
}
}
System.out.println(sum);
4번
// 4번
while(true) {
int one = (int)(Math.random() * 6 + 1);
int two = (int)(Math.random() * 6 + 1);
System.out.println("1 번째 : " + one);
System.out.println("2 번째 : " + two);
if(one + two == 5) {
System.out.println("주사위 합 : " + (one + two));
break;
}
}
5번
// 5번
for(int i = 0; i<=10; i++) {
for(int j=0;j<=10;j++) {
if(4*i + 5*j == 60) {
System.out.println("("+i+","+j+")");
}
}
}
6번
// 6번
for(int i=0;i<5;i++) {
for(int j =0;j<=i;j++) {
System.out.print("*");
}
System.out.println();
}
7번
// 7번
int money = 0;
while(true) {
Scanner sc = new Scanner(System.in);
System.out.println("-------------------------------");
System.out.println("1.예금 | 2.출금 | 3.잔고 | 4. 종료");
System.out.println("-------------------------------");
System.out.print("선택>");
int select = Integer.parseInt(sc.nextLine());
switch(select){
case 1:
System.out.print("예금액>");
money += Integer.parseInt(sc.nextLine());
break;
case 2:
System.out.print("출금액>");
money -= Integer.parseInt(sc.nextLine());
break;
case 3:
System.out.print("잔고>");
System.out.println(money);
break;
case 4:
System.out.print("프로그램 종료");
return;
}
728x90
반응형
'Java' 카테고리의 다른 글
| 4/7 - 클래스 (1) | 2025.04.12 |
|---|---|
| 이것이 자바다 - 챕터5 연습 문제 (0) | 2025.04.05 |
| 이것이 자바다 - 챕터3 연습 문제 (0) | 2025.04.05 |
| 4/4 공부 기록 - 참조 타입, 클래스 (8) | 2025.04.05 |
| 4/3 - 변수, 조건문, 반복문 (0) | 2025.04.05 |