import java.util.Scanner;
public class Foreach {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
String y = null;
String str = null;
//최초 한번 무조건 실행되는 do while 문
do{
int i,j;
System.out.println("i ="); //i 값 받고
i = sc.nextInt();
System.out.println("j ="); //j 값 받고
j = sc.nextInt();
System.out.println("부호 입력 + ,ㅡ - , * , / ");
str = sc.next(); //부호 입력 값 받고
if(str.equals("+")) {
System.out.println("a+b =" + (i + j));
}else if(str.equals("-")){
System.out.println("a-b =" + (i - j));
}else if(str.equals("*")) {
System.out.println("a*b =" + (i * j));
}else if(str.equals("/")) {
System.out.println("a/b =" + (i / j));
}else {
System.out.println("잘못 입력했다오");
}
System.out.println("더 계산 하실겁니까? y"); //탈출 할건지 물어본다
y = sc.next();
}while(y.equals("y")); //y 가 입력되면 탈출된다.
System.out.println("끗");
}
}
출력값은
i =
5
j =
4
부호 입력 + - * /
+
a+b =9
더 계산 하실겁니까? y
'java' 카테고리의 다른 글
java - 별모양으로 도형 출력 (0) | 2020.08.04 |
---|---|
java - 종이를 접은 횟수 출력과 사각형의 갯수 for문 이용 (0) | 2020.08.04 |
java -구구단 출력하기 (0) | 2020.08.04 |
java - 자바의 개념과 접근 제어자 및 데이터 타입 (0) | 2020.08.03 |
이클립스 사용시 단축키 !! (0) | 2020.08.03 |