달력

62025  이전 다음

  • 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


 
문제 조건

90 점 이상 "A학점"    90 ~ 99
80 점 이상 "B학점"    80 ~ 89
70 점 이상 "C학점"    70 ~ 79
60 점 이상 "D학점"    60 ~ 69
60 점 이하 "F학점"    0 ~ 59

0 ~ 100 사이일 때만 학점 출력
범위 밖이면 "잘못 입력" 출력





첫번째 풀이

내가 직접푼 풀이

class SwitchEx2
{
 public static void main(String[] args)
 {
  int a = Integer.parseInt( args[0] );

  if ( a >= 100 || a <= -1 ) System.out.println( "잘못 입력" );
  else switch( a / 10 )
  {
  case 9 : System.out.println( "A학점" );
  break;
  case 8 : System.out.println( "B학점" );
  break;
  case 7 : System.out.println( "C학점" );
  break;
  case 6 : System.out.println( "D학점" );
  break;
  default : System.out.println( "F학점" );
  }
 }
}



두번째 풀이

선생님 풀이


class SwitchEx2
{
 public static void main(String[] args)
 {
  int a = Integer.parseInt( args[0] );

if( a >= 0 && a <= 100 )
{
switch( a / 10 )
  {
  case 9 : System.out.println( "A학점" );
  break;
  case 8 : System.out.println( "B학점" );
  break;
  case 7 : System.out.println( "C학점" );
  break;
  case 6 : System.out.println( "D학점" );
  break;
  default : System.out.println( "F학점" );
  }
}
  else
  {
    System.out.println( "잘못 입력" );
   }
  }
}




















'매니저 > JAVA1' 카테고리의 다른 글

JAVA1 for문 예제2 (임시저장)  (0) 2011.12.23
JAVA1 for문 예제1 (임시저장)  (0) 2011.12.23
JAVA1 switch 예제1  (0) 2011.12.08
JAVA1 else 예제2  (0) 2011.12.08
JAVA1 fi ~ else 예제1  (0) 2011.12.08
Posted by cdprkr2077
|