한 직장인의 연간 근로소득에 대한 소득세를 계산하는 프로그램을 설계하고 작성하라.
근로소득에 대한 소득세는 다음과 같다.
연간 근로소득은 입력받아야 한다.
import java.util.Scanner;
public class Tax_calculate {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
double in_tax; //in_tax : 소득세
System.out.print("연간 근로소득을 입력하세요 : ");
int salary = scan.nextInt(); //salary : 근로소득
if ( salary <= 20000000 ) in_tax = salary * 0.05;
else if ( salary <= 40000000 ) in_tax = salary * 0.15;
else if ( salary <= 80000000 ) in_tax = salary * 0.25;
else in_tax = salary * 0.4;
System.out.println("소득세는 "+(int)in_tax+"원 입니다.");
}
}
salary
입니다.in_tax
이고 income tax
의 준말입니다.if~else if~else문
을 사용하여 ~을 초과하고
의 조건식은 생략하였습니다. if
에서 else if
로, else if
에서 또 다음의 else if
로 넘어갔다는 것은 이미 앞의 조건에 맞지 않다는 것을 의미하기 때문에 굳이 조건식을 늘일 필요가 없습니다.%5 == * 0.05
로 계산합니다.연간 근로소득을 입력하세요 : 20000000
소득세는 1000000원 입니다.
연간 근로소득을 입력하세요 : 40000000
소득세는 6000000원 입니다.
연간 근로소득을 입력하세요 : 80000000
소득세는 20000000원 입니다.
연간 근로소득을 입력하세요 : 10000000
소득세는 500000원 입니다.
연간 근로소득을 입력하세요 : 100000000
소득세는 40000000원 입니다.