Java Reference
In-Depth Information
12 System.out.print(ÐPlease enter your
income: Ñ);
13 double income = in.nextDouble();
14
15 System.out.print(ÑAre you married?
(Y/N) Ñ);
16 String input = in.next();
17 int status;
18 if (input.equalsIgnoreCase(ÐYÑ))
19 status = TaxReturn.MARRIED;
20 else
21 status = TaxReturn.SINGLE;
22 TaxReturn aTaxReturn = new
TaxReturn(income, status);
23
24 System.out.println(ÐTax: Ñ
25 + aTaxReturn.getTax());
26 }
27 }
Output
Please enter your income: 50000
Are you married? (Y/N) N
Tax: 11211.5
201
202
S ELF C HECK
5.
The if/else/else statement for the earthquake strength first
tested for higher values, then descended to lower values. Can you
reverse that order?
6.
Some people object to higher tax rates for higher incomes, claiming
that you might end up with less money after taxes when you get a
raise for working hard. What is the flaw in this argument?
C OMMON E RROR 5.2: The Dangling Else Problem
When an if statement is nested inside another if statement, the following error
may occur.
if (richter >= 0)
Search WWH ::




Custom Search