Java Reference
In-Depth Information
The only thing we need to know is whether the value is positive, negative, or zero. The
output is self-explanatory.
The following example shows how to use strings in Boolean expressions as part of an if
statement.
EXAMPLE 4-24
The following program assigns standard exemption depending on the filing status of a person.
import java.util.*;
4
public class Example4_24
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
String status1;
String status2 = "";
double standardExemption = 0.0;
System.out.print("Enter the tax filing status: ");
status1 = console.next();
System.out.println();
if (status1.compareTo("married") == 0)
{
System.out.print("Enter filing joint/separately: ");
status2 = console.next();
System.out.println();
if (status2.compareTo("joint") == 0)
standardExemption = 12000.00;
else if (status2.compareTo("separately") == 0)
standardExemption = 6000.00;
else
System.out.println("Invalid status.");
}
else if (status1.compareTo("single") == 0)
standardExemption = 9000.00;
else if (status1.compareTo("headHouseHold") == 0)
standardExemption = 10000.00;
else
System.out.println("Invalid status.");
System.out.println("Filing status: " + status1 + " " + status2);
System.out.printf("Standard exemption: $%.2f %n",
standardExemption);
}
}
 
Search WWH ::




Custom Search