티스토리 뷰
import java.util.Scanner;
public class testcoding {
public static void main(String[] args) {
int kor,eng,math;
//입력값 저장
Scanner scan=new Scanner(System.in);
System.out.print("국어 점수 : ");
kor=scan.nextInt();
System.out.print("영어 점수 : ");
eng=scan.nextInt();
System.out.print("수학 점수 : ");
math=scan.nextInt();
/*
* int a=10; 메모리 생성과 값 입력
* int a;
* a=10;
*
* int a=10, b=20, c=30;
*
* int a,b,c;
* a=10;
* b=20;
* c=30;
*/
//평균구하기
int avg = (kor+eng+math)/3;
//등급(학점)
char score;
if(avg >=90)
{
score='A';
}
else if(avg >=80)
{
score='B';
}
else if(avg >=70)
{
score='C';
}
else if(avg >=60)
{
score='D';
}
else
{
score='F';
}
System.out.println("총점 : "+(kor+eng+math));
System.out.println("평균 : "+(kor+eng+math)/3.0);
System.out.printf("평균 : %.2f\n",(kor+eng+math)/3.0);
System.out.println("학점 : "+score);
}
}
3과목 점수를 받아서
각 총점, 평균을 매기고
해당 점수에 맞는 학점을 출력하는 프로그램.
사실 switch~case가 더 쉽다...
단지 if~else if~else 구문을 공부하기엔 이거만한것도 없다고 개인적으로 생각.
'Programming? > JAVA' 카테고리의 다른 글
| 배열에서 값 빼오기, for-each 방식 (0) | 2012.07.03 |
|---|---|
| switch~case를 이용한 계산기 (0) | 2012.07.03 |
| 가위바위보 게임 (0) | 2012.07.03 |
| 로또 숫자 출력 (0) | 2012.07.03 |
| 숫자맞추기 (0) | 2012.07.03 |
- Total
- Today
- Yesterday
- League of legends
- PSP
- java
- Talesweaver_Palshu
- PS VITA
- 무사헌터G
- Android
- spring
- jdbc
- C Programming
- HTML
- XML
- 이건사야되!
- GOD EATER2
- 포세리앙 시밤...
- jsp
- DnF_카인
- Unleashed
- oracle
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |