格式标志转换不匹配异常

编写一个程序,输入三件物品的名称、数量和价格。名称可能包含空格。输出税率为 6.25% 的票据。所有价格都应输出到小数点后两位。帐单格式为列式,名称为 30 个字符,数量为 10 个字符,价格为 10 个字符,总数为 10 个字符。示例输入和输出如下所示:


import java.util.Scanner;


public class ProjectLab {


    public static final double SALES_TAX = 8.625;


    public static void main(String[]args) {


        Scanner input = new Scanner(System.in);


        String item1, item2, item3;


        int quantity1, quantity2, quantity3;


        double price1, price2, price3;


        //Input for the first Item

        System.out.println("Input the name of item 1: ");

        item1 = input.nextLine();


        System.out.println("Input quantity of item 1: ");

        quantity1 = input.nextInt();


        System.out.println("Input price of item 1: ");

        price1 = input.nextDouble();


        String junk = input.nextLine(); //Junk Line

        //Input for the second Item

        System.out.println("Input name of item 2: ");

        item2 = input.nextLine();


        System.out.println("Input quantity of item 2: ");

        quantity2 = input.nextInt();


        System.out.println("Input price of item 2: ");

        price2 = input.nextDouble();


        String junk2 = input.nextLine(); //Junk line 2

        //Input for the third item

        System.out.println("Input name of item 3: ");

        item3 = input.nextLine();


        System.out.println("Input quantity of item 3: ");

        quantity3 = input.nextInt();


        System.out.println("Input price of item 3: ");

        price3 = input.nextDouble();


        double subtotal1 = price1 * quantity1;

        double subtotal2 = price2 * quantity2;

    }

}


梦里花落0921
浏览 120回答 2
2回答

慕无忌1623718

你需要用另一个 % 来逃避你的 %System.out.printf("8.265%% Sales tax %.2f\n        ", tax);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java