달력

102025  이전 다음

  • 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





문제



class VaruableStydy
{
 public static void main(String[] args)
 {

  int kor = 81;   // 국어 점수
  int eng = 75;   // 영어 점수
  int mat = 91;   // 수학 점수

  // 국어 : 81점
  // 영어 : 75점
  // 수학 : 91점
  // 총점 : ---점
  // 평균 : --.-점     // 단 소수점이 출력되도록
 }
}






풀이...


이게 정말 될줄은 꿈에도 몰랐네...

이런 방식은 추천하고 싶지 않다..


class VaruableStydy
{
 public static void main(String[] args)
 {

  int kor = 81;   // 국어 점수
  int eng = 75;   // 영어 점수
  int mat = 91;   // 수학 점수

  System.out.println( "국어 : " + kor + "점" ); 
  System.out.println( "영어 : " + eng + "점" );
  System.out.println( "수학 : " + mat + "점" );
  System.out.println( "총점 : " + (kor + eng + mat) );
  System.out.println( "평균 : " + ( ((double)kor + eng + mat) ) / 3 );

  }
}



안좋은 다른 예

한가지 문장(?)이 반복되면 나중에 수정할때 피곤해진다.

class VaruableStydy
{
 public static void main(String[] args)
 {

  int kor = 81;   // 국어 점수
  int eng = 75;   // 영어 점수
  int mat = 91;   // 수학 점수

  int tot = kor + eng + mat;
  double avg = (kor + eng + mat) / 3.0;

  System.out.println( "국어 : " + kor + "점" );
  System.out.println( "영어 : " + eng + "점" );
  System.out.println( "수학 : " + mat + "점" );
  System.out.println( "총점 : " + tot + "점" );
  System.out.println( "평균 : " + avg + "점" );
 
 }
}


class VaruableStydy
{
 public static void main(String[] args)
 {

  int kor = 81;   // 국어 점수
  int eng = 75;   // 영어 점수
  int mat = 91;   // 수학 점수

 

  System.out.println( "국어 : " + kor + "점" );
  System.out.println( "영어 : " + eng + "점" );
  System.out.println( "수학 : " + mat + "점" );
  System.out.println( "총점 : " + (kor + eng + mat)  + "점" );
  System.out.println( "평균 : " + (kor + eng + mat) / 3.0 + "점" );
 
 }
}





















만점에 가까운 답

class VaruableStydy
{
 public static void main(String[] args)
 {

  int kor = 81;   // 국어 점수
  int eng = 75;   // 영어 점수
  int mat = 91;   // 수학 점수

  int tot = kor + eng + mat;
  double avg = tot / 3.0;

  System.out.println( "국어 : " + kor + "점" );
  System.out.println( "영어 : " + eng + "점" );
  System.out.println( "수학 : " + mat + "점" );
  System.out.println( "총점 : " + tot + "점" );
  System.out.println( "평균 : " + avg + "점" );
 
 }
}












Posted by cdprkr2077
|