Skip to content

Instantly share code, notes, and snippets.

@FeelingXD
Last active January 5, 2023 14:06
Show Gist options
  • Save FeelingXD/5fc775c3fc8ae6efeec0d08bdf7baeae to your computer and use it in GitHub Desktop.
Save FeelingXD/5fc775c3fc8ae6efeec0d08bdf7baeae to your computer and use it in GitHub Desktop.
/*
작성자: 고지민
*/
import java.util.Scanner;
public class Main {
private static final int[] rates = {6, 15, 24, 35, 38, 40, 42, 45};
private static final int[] standards = {0, 12_000_000, 46_000_000, 88_000_000, 150_000_000, 300_000_000, 500_000_000, 1_000_000_000};
private static final int[] deductibles = {0, 1_080_000, 5_220_000, 14_900_000, 19_400_000, 25_400_000, 35_400_000, 65_400_000};
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
System.out.println("[과세금액 계산 프로그램]");
int index=0;
int tax_sum=0;
long salary=inputSalary("연소득을 입력해 주세요.:",input,0,Long.MAX_VALUE);
long temp=salary;
for(int i=0;0<temp&&i<standards.length;i++){
if(i!=standards.length-1)
System.out.printf("%10d * %2d%% = %15d\n", Math.min(standards[i + 1]-standards[i] ,temp), rates[i], Math.min(standards[i + 1]-standards[i],temp) * rates[i] / 100);
else {
System.out.printf("%10d * %2d%% = %15d\n", temp, rates[i], temp * rates[i] / 100);
}
tax_sum+=Math.min(standards[i + 1]-standards[i],temp) * rates[i] / 100;
temp-=Math.min(standards[i + 1]-standards[i],temp);
index=i;
}
System.out.println();
System.out.print("[세율에 의한 세금]:");
System.out.printf("%17d\n",tax_sum);
System.out.print("[누진공제 계산에 의한 세금]:");
System.out.printf("%10d\n", index==0?0: salary* rates[index] / 100-deductibles[index]);
}
public static long inputSalary(String message,Scanner input,long min,long max){
try {
System.out.printf(message);
long value= input.nextLong();
if (value<min||value>max)
throw new Exception();
return value;
}catch (Exception e){
System.out.println("다시 입력해주세요.");
return inputSalary(message,input,min,max);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment