Constants with final

Lab Java Beginner 10 points

Declare final double TAX_RATE = 0.18;. Read a price and print the tax and the total, each with 2 decimals.

Input

One decimal number.

Output

Two lines: tax, total.

Example

Input

100

Output

18.00
118.00
Sample input available Sample output available
Editor
Java

Hints

final means the variable can't be reassigned.

Solution explanation

Constants make magic numbers readable and prevent accidental changes.

Show solution
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final double TAX_RATE = 0.18;
        Scanner sc = new Scanner(System.in);
        double price = sc.nextDouble();
        double tax = price * TAX_RATE;
        System.out.printf("%.2f%n", tax);
        System.out.printf("%.2f%n", price + tax);
    }
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD