Concept

How can a Java program read income and children inputs while rejecting negative values?

ComputerScienceOne / Life & Taxes

"27.3.2. Life & Taxes Let’s adapt the conditional statements we developed in Section 3.6.4 into a full Java program. The first thing we need to do is establish the variables we’ll need and read them in from the user. At the same time we can check for bad input (negative values) for both the inputs.\n\n1 Scanner s = new Scanner(System.in);\n\n2 double income, baseTax, numChildren, credit, totalTax;\n\n3\n\n4 System.out.println(\"Please enter your Adjusted Gross Income: \");\n\n5 income = s.nextDouble();\n\n6\n\n7 System.out.println(\"How many children do you have?\");\n\n8 numChildren = s.nextDouble();\n\n9\n\n10 if(income < 0 || numChildren < 0) {\n\n11 System.out.println(\"Invalid inputs\");\n\n12 System.exit(1);\n\n13 }"

Related Ideas

How can a Java program read income and children inputs while rejecting negative values? | ComputerScienceOne | Bifalgorithm | Bifalgorithm