본문 바로가기

프로그래밍/자바소스 및 자료

[자바소스] 성적 확인 프로그램


1. 소스 설명
 switch() 문을 이용한 성적 확인 프로그램입니다.
점수를 넣게 되면 +,0 성적까지 알수 있도록 작성하였습니다.


2.소스 :
 import java.util.Scanner;

public class Print {
 public static void main(String[] args){
  Scanner input=new Scanner(System.in);
  System.out.print("성적을 입력하세요 : ");
  float point=input.nextFloat();
  System.out.printf("당신의 성적은 %s 입니다.", grade(point));
 }
 
 private static String grade(float point){
  char plus=plus(point);
  int grade=(int)point/10;
  switch(grade){
   case 10:
   case 9:
    return "A"+plus;
   case 8:
    return "B"+plus;
   case 7:
    return "C"+plus;
   case 6:
    return "D"+plus;
   default :
    return "F";
  }
 }
 
 private static char plus(float point){
  return (point%10)>5? '+':null;
 }
}



3.결과