2005-10-18

Lab If-else

public class display3_1
{
public static void main(String[] args)
{
double netIncome, tax, fivePercentTax, tenPercentTax;

System.out.println("Enter net imcome.\n" + "Do not include a dollar sign o
r any commas.");
netIncome = 30000;

if (netIncome <= 15000)
tax=0;
else if ((netIncome>15000)&&(netIncome<=30000))
tax=(0.05*(netIncome-15000));
else
{
fivePercentTax = 0.05*15000;
tenPercentTax = 0.10*(netIncome-30000);
tax = (fivePercentTax + tenPercentTax);
}
System.out.println("Tax due = "+tax);
//用println,後面就要用"+",不可使用變數
}
}

===顯示結果===
Enter net imcome.
Do not include a dollar sign or any commas.

Tax due = 750.0

0 Comments:

張貼留言

<< Home