Java 由于进动错误丢失,代码执行停止 我是NoOB,所以请原谅我的NOOB缩进,如果他们不符合标准。如有任何关于缩进的建议,将不胜感激。所以我的问题是,在switch语句之后,计算机没有读取下一行代码。这是最后的发票金额等式,并将其打印到屏幕上。还有一个错误是:

Java 由于进动错误丢失,代码执行停止 我是NoOB,所以请原谅我的NOOB缩进,如果他们不符合标准。如有任何关于缩进的建议,将不胜感激。所以我的问题是,在switch语句之后,计算机没有读取下一行代码。这是最后的发票金额等式,并将其打印到屏幕上。还有一个错误是:,java,cloud9,Java,Cloud9,InvoiceApp.java:34:错误:可能丢失精度 开关(折扣百分比) ^ 必填项:int 发现:双 1错误 正如您将看到的,我将变量折扣百分比指定为双精度。所以我不确定为什么会有错误。任何帮助都将不胜感激。非常感谢。这是到目前为止我的代码 import java.util.Scanner; public class InvoiceApp { public static void main(String[] args) { //Declare variab

InvoiceApp.java:34:错误:可能丢失精度
开关(折扣百分比)
^
必填项:int
发现:双
1错误

正如您将看到的,我将变量折扣百分比指定为双精度。所以我不确定为什么会有错误。任何帮助都将不胜感激。非常感谢。这是到目前为止我的代码

import java.util.Scanner;

public class InvoiceApp
{
    public static void main(String[] args)
    {
        //Declare variables and Scanner object
        Scanner input = new Scanner(System.in);

        double subtotal, discountAmount, discountPercent, invoiceTotal;
        int customerType;


        //Display a welcome message
        System.out.println("Welcome to the invoice calculator app!");


       //Prompt user for customer type
       System.out.print("Please enter the customer type(1 for Silver, 2 for          Gold, or 3 for Platinum): ");


    //Read customer type
    customerType = input.nextInt();

    //Prompt user for subtotal   
    System.out.print("Please enter the subtotal amount: ");

    //Read subtotal
    subtotal = input.nextDouble();

    //Calculate Discount Rate

    switch(discountPercent)

    { //start switch block

    case 1:

    {

        if (subtotal >= 500)
            {
            discountPercent = .20;
            System.out.print("Your discount rate is .20"); 
            break;
            } 

        else if (subtotal >= 250)
            { 
            discountPercent = .15;
            System.out.print("Your discount rate is 15% !"); 
            break; 
            }

        else if (subtotal >= 100)
            {
            discountPercent = .10;
            System.out.print("Your discount rate is 10%!"); break;
            } 

        else if(subtotal < 100)
            {
            discountPercent = .0;
            System.out.print("Sorry, your discount rate is 0%!"); break;
            } 

        }//end of case one block
        case 2:
        {    
            {
            discountPercent = .2;
            System.out.print("Your discount rate is 20%!"); 
            break;
            } 
        }//end of case two block


        case 3:
        {

        if (subtotal >= 500)
            {
            discountPercent = .50;
            System.out.print("Woop woop, your discount rate is 50%!"); 
            break;
            }

        else if (subtotal < 500)
            {
            discountPercent = .40;
            System.out.print("Your discount rate is 40%!"); break;
            } 

        }//end of case three block
    default:
    {    
        {
        discountPercent = .5;
        System.out.print("Congratulations! Your discount rate is 50 %! ");                                   } 
    }

 }//end of switch discountPercent

//Calculate Invoice Total
discountAmount = subtotal * discountPercent;
invoiceTotal = subtotal - discountAmount;

System.out.println("Total: " + invoiceTotal);

//Display thank you message
System.out.println("Thank you!");


//Format and display the results
System.out.print("Jump around! Jump around! Your invoice total is: " + invoiceTotal);


}//end of main
}//end of class
import java.util.Scanner;
公共类InvoiceApp
{
公共静态void main(字符串[]args)
{
//声明变量和扫描对象
扫描仪输入=新扫描仪(System.in);
双倍小计、折扣金额、折扣百分比、发票总额;
int客户类型;
//显示欢迎信息
System.out.println(“欢迎使用发票计算器应用程序!”);
//提示用户输入客户类型
System.out.print(“请输入客户类型(1表示银,2表示金,或3表示白金):”;
//读取客户类型
customerType=input.nextInt();
//提示用户进行小计
系统输出打印(“请输入小计金额:”);
//阅读小计
小计=input.nextDouble();
//计算贴现率
开关(折扣百分比)
{//启动开关块
案例1:
{
如果(小计>=500)
{
折扣百分比=.20;
系统输出打印(“您的折扣率为.20”);
打破
} 
否则,如果(小计>=250)
{ 
折扣百分比=.15;
系统输出打印(“您的折扣率为15%!”;
打破
}
否则,如果(小计>=100)
{
折扣百分比=.10;
System.out.print(“您的折扣率为10%!”);中断;
} 
否则,如果(小计<100)
{
折扣百分比=.0;
System.out.print(“对不起,您的折扣率是0%!”);中断;
} 
}//案例一结束
案例2:
{    
{
折扣百分比=.2;
系统输出打印(“您的折扣率为20%!”;
打破
} 
}//案例二结束
案例3:
{
如果(小计>=500)
{
折扣百分比=.50;
系统输出打印(“呜呜呜,你的折扣率是50%!”;
打破
}
否则,如果(小计<500)
{
折扣率=0.40;
System.out.print(“您的折扣率为40%!”);中断;
} 
}//案例三结束
违约:
{    
{
折扣百分比=.5;
System.out.print(“恭喜!您的折扣率是50%!”);}
}
}//交换机结束折扣百分比
//计算发票总额
折扣金额=小计*折扣百分比;
发票总额=小计-折扣金额;
系统输出打印项次(“总计:+invoiceTotal”);
//显示感谢信息
System.out.println(“谢谢!”);
//格式化并显示结果
System.out.print(“跳转!跳转!您的发票总额为:+invoiceTotal”);
}//干管末端
}//下课

switch语句不能与double一起使用

请参阅本教程:

一个开关可以处理byte、short、char和int原语数据 类型。它还适用于枚举类型(在Enum中讨论) 类型)、字符串类和一些特殊的包装类 某些基本类型:字符、字节、短字符和整数 (在数字和字符串中讨论)


这是一个编译错误。此代码无法运行。
switch
不允许使用
double
,您必须使用
if
语句谢谢各位,所以我根本不能在switch语句中使用double?还有您系统中的一些文本输出。out与折扣%不匹配。请理解:这些东西都是超基本的。你通过读书来了解他们;而不是问我们有无数次记录在案的事情。