A local pizza shop is selling a large pizza for $9.99. Given the number of pizzas to order as input, output the subtotal for the pizzas, and then output the total after applying a sales tax of 6%.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
System.out.printf("Subtotal: %.2f\n", yourValue);
Ex: If the input is:
3
the output is:
Subtotal: $29.97
Total due: $31.77
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter the number of pizzas to be ordered");
int n=input.nextInt();
double amount=9.99*n;
double total=0.06*amount+amount;
System.out.println("SubTotal:%.2f "+amount);
System.out.println("Total Due: %0.2f "+total);
}
}
Comments
Leave a comment