1.입출금 문제
Scanner scan = new Scanner(System.in);
int save = 0;
int out = 0;
int show = 0;
int moeny = 0;
while (true) {
System.out.println("---------------------------------");
System.out.println("1.예금 | 2.출금 | 3.잔금 | 4.종료");
System.out.println("---------------------------------");
System.out.println("선택> ");
int input = scan.nextInt();
if (input == 1) {
System.out.print("예금액> ");
save = scan.nextInt();
moeny += save;
} else if (input == 2) {
System.out.print("출금액> ");
out = scan.nextInt();
moeny -= out;
} else if (input == 3) {
System.out.print("잔고>" + moeny);
} else if (input == 4) {
break;
}
}
System.out.println("프로그램종료");
}
}
2.학생평균구하기
boolean run = true;
int studentNum = 0;
int[] scores = null;
Scanner scanner = new Scanner(System.in);
while (run) {
System.out.println("-------------------------------------------------------");
System.out.println("1.학생수 | 2.점수입력 | 3.점수리스트 | 4.분석 | 5.종료");
System.out.println("-------------------------------------------------------");
System.out.print("선택> ");
int selectNo = scanner.nextInt();
if (selectNo == 1) {
System.out.println("학생수> ");
int scount = scanner.nextInt();
scores = new int[scount];
} else if (selectNo == 2 && scores != null) {
for (int i = 0; i < scores.length; i++) {
System.out.println("scores[" + i + "]>");
scores[i] = scanner.nextInt();
}
} else if (selectNo == 3 && scores != null) {
for (int k=0; k
System.out.println("scores[" + k + "]:" + scores[k]);
}
} else if (selectNo == 4 && scores != null) {
int max = 0;
count=0;tot=0;
for(int i = 0; i< scores.length; i++) {
count+=1;
;tot+=scores[i];
if(max < scores[i]) {
max = scores[i];
}
}
double avg = (tot/count);
System.out.println("최고 점수: " + max);
System.out.println("평균 점수: " + avg);
} else if (selectNo == 5) {
run = false;
}
}
}
}
'web_배우고익히고 > 4.JAVA' 카테고리의 다른 글
Java 연습문제_사이트 (0) | 2020.01.07 |
---|---|
Class란 (0) | 2020.01.07 |
Java 참조 타입 (0) | 2020.01.06 |
foreach(for문 업그레이드) (0) | 2020.01.06 |
Java 연습문제(While 숫자 퀴즈 게임) (0) | 2020.01.06 |