캐스트 연산자 및 연산 연습 - 실수령액 구하기

2023. 12. 17. 13:44· LANGUAGE/└ Java

문제 

급여액이 주어졌을 때 각종 세금과 수령액을 계산하는 계산기를 구현합시다

급여액 : 300만원
국민연금 : 급여액의 4.5%
건강보험료 : 급여액의 7.09%
장기요양보험료 : 건강보험료의 12.81%
고용보험료 : 급여액의 0.9%

- 출력 순서
실수령액
국민연금
건강보험료
장기요양보험료
고용보험료


[Java 코드]

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);	
		System.out.print("월봉 입력 : ");
		int salary = sc.nextInt();	//월봉 입력 받기
		
		float pension = salary * 0.045f;
		float healthInsurance = salary * 0.0709f;
		float careInsurance = healthInsurance * 0.1281f;
		float empInsurance = salary * 0.009f;
		
		int total = (int)(salary - (pension + healthInsurance + careInsurance + empInsurance));
		
		System.out.println("실수령액 : " + total + "원");
		System.out.println("국민연금 : " + (int)pension + "원");
		System.out.println("건강보험료 : " + (int)healthInsurance + "원");
		System.out.println("장기요양보험료 : " + (int)careInsurance + "원");
		System.out.println("고용보험료 : " + (int)empInsurance + "원");
	}
}

 

- 월봉을 입력 받을 수 있는 형태로 변경하였음.

- 출력 시 함수 형태가 아닌 정수형태로 바꾸었음. (Cast 연산자)


[출력결과]

 

 

 

개인 공부 기록용 입니다:)

728x90