Please Enable JavaScript!
Mohon Aktifkan Javascript![ Enable JavaScript ]

[Java 소스] if ~ else 를 이용한 계산기

2010. 3. 30. 14:45Source/Java_source

728x90


import java.util.*;

class Calc_j {
 public static void main(String args[]) {
  Scanner key = new Scanner(System.in);

  int a,b;
  String c;
  char d;

  System.out.print("정수 입력 : ");
  a = key.nextInt();
  System.out.print("정수 입력 : ");
  b = key.nextInt();

  System.out.print("연산 (+,-,*,/ 중) : ");
  c = key.next();
  d = c.charAt(0);

  if(d=='+')
   System.out.println(a + " + " + b + " = " + (a+b));
  else if (d=='-')
   System.out.println(a + " - " + b + " = " + (a-b));
  else if (d=='*')
   System.out.println(a + " * " + b + " = " + (a*b));
  else if (d=='/')
   System.out.println(a + " / " + b + " = " + (a/b));
  else
   System.out.println("잘못 입력했습니다");
 }
}

728x90

'Source > Java_source' 카테고리의 다른 글

[Java 소스]입력 받은 값 중 가장 큰 값 출력  (0) 2010.03.30
[Java 소스] x^y 구하는 소스  (0) 2010.03.26