Jave 使用简单Java程序时遇到问题

Jave 使用简单Java程序时遇到问题,jave,Jave,试图编写一个Java程序来满足这一点:Duke Shirts公司销售的Java t恤每件售价为24.95美元,但数量折扣如下:1件或2件衬衫,不打折,总运费为10.00美元3-5件衬衫,折扣为10%,总运费为8.00美元6-10件衬衫,折扣为20%,总运费为5.00美元11件或更多衬衫,折扣为30%,免费送货。编写一个Java程序,提示用户所需的衬衫数量。然后,程序应打印衬衫的扩展价格、运费和订单的总成本。在适当的情况下使用货币格式 这是我的密码: import java.lang.Math;

试图编写一个Java程序来满足这一点:Duke Shirts公司销售的Java t恤每件售价为24.95美元,但数量折扣如下:1件或2件衬衫,不打折,总运费为10.00美元3-5件衬衫,折扣为10%,总运费为8.00美元6-10件衬衫,折扣为20%,总运费为5.00美元11件或更多衬衫,折扣为30%,免费送货。编写一个Java程序,提示用户所需的衬衫数量。然后,程序应打印衬衫的扩展价格、运费和订单的总成本。在适当的情况下使用货币格式

这是我的密码:

import java.lang.Math;
import java.util.Scanner;

public class Excercise2_3 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("How many shirts do you need?");
        double shirts = input.nextInt();
        if (shirts <= 2)
            System.out.printf("The extended cost is : $%.2", (shirts * 24.95));
            System.out.printf("The shipping charges are $10.00");
            System.out.printf("The total cost is : $%.2", (shirts * 24.95) + 10);
        if (shirts > 2 && shirts <= 5)
            System.out.printf("The extended cost is : $%.2", ((shirts * 24.95)*.10));
            System.out.printf("The shipping charges are $8.00");
            System.out.printf("The total cost is : $%.2", ((shirts * 24.95)*.10) + 8);
        if (shirts > 5 && shirts <= 10)
            System.out.printf("The extended cost is : $%.2", ((shirts * 24.95)*.20));
            System.out.printf("The shipping charges are $5.00");
            System.out.printf("The total cost is : $%.2", ((shirts * 24.95)*.20) + 5);
        if (shirts > 10)
            System.out.printf("The extended cost is : $%.2", ((shirts * 24.95)*.00));
            System.out.printf("Shipping is free!");
            System.out.printf("The total cost is : $%.2", ((shirts * 24.95)*.30));

    }

}
import java.lang.Math;
导入java.util.Scanner;
公开课练习2_3{
公共静态void main(字符串[]args){
//TODO自动生成的方法存根
扫描仪输入=新扫描仪(System.in);
System.out.println(“您需要多少件衬衫?”);
double shirts=input.nextInt();
if(衬衫2和衬衫5和衬衫10)
System.out.printf(“扩展成本为:$%.2”,((衬衫*24.95)*.00));
System.out.printf(“免费送货!”);
System.out.printf(“总成本为:$%.2”((衬衫*24.95)*.30));
}
}

有人能解释一下为什么编译不正确吗?谢谢

if语句周围缺少大括号。此外,printf格式字符串应为
%.2f
。您缺少了
f
和换行符

import java.util.Scanner;

public class TempApp {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("How many shirts do you need?");
        double shirts = input.nextInt();
        if (shirts <= 2) {
            System.out.printf("The extended cost is : $%.2f\n", (shirts * 24.95));
            System.out.printf("The shipping charges are $10.00\n");
            System.out.printf("The total cost is : $%.2f\n", (shirts * 24.95) + 10);
        }
        if (shirts > 2 && shirts <= 5) {
            System.out.printf("The extended cost is : $%.2f\n", ((shirts * 24.95) * .10));
            System.out.printf("The shipping charges are $8.00\n");
            System.out.printf("The total cost is : $%.2f\n", ((shirts * 24.95) * .10) + 8);
        }
        if (shirts > 5 && shirts <= 10) {
            System.out.printf("The extended cost is : $%.2f\n", ((shirts * 24.95) * .20));
            System.out.printf("The shipping charges are $5.00\n");
            System.out.printf("The total cost is : $%.2f\n", ((shirts * 24.95) * .20) + 5);
        }
        if (shirts > 10) {
            System.out.printf("The extended cost is : $%.2f", ((shirts * 24.95) * .00));
            System.out.printf("Shipping is free!");
            System.out.printf("The total cost is : $%.2f", ((shirts * 24.95) * .30));
        }
    }
}
import java.util.Scanner;
公共类临时应用程序{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(System.in);
System.out.println(“您需要多少件衬衫?”);
double shirts=input.nextInt();
if(衬衫2和衬衫5和衬衫10){
System.out.printf(“扩展成本为:$%.2f”,((衬衫*24.95)*.00));
System.out.printf(“免费送货!”);
System.out.printf(“总成本为:$%.2f”((衬衫*24.95)*.30));
}
}
}

欢迎来到堆栈溢出。堆栈溢出不是一个用来收集CS101作业的站点。如果你有一个问题,你可以明确地陈述,并作出一个最低限度的可行的例子,人们会很乐意帮助你。我会提到这一点,很明显,这并不是为了挤满源代码,这可以从我发布的太长的代码中看出。它完成了95%,我花了很多时间。我寻求的帮助是克莱三句话的回答,我不是在找人帮我做作业。不过还是要谢谢你…以后如果我有问题,我会发布简短的代码片段。我不想让我的教授认为我在作弊。我的意思是,你的问题是“这是我收到的作业,有人能调试我的代码吗?”仅仅因为有人回应并不意味着你正确地使用了这个网站。如果你要发布一个关于这个问题的概括性例子,并解释为什么你感到困惑,那么它可能会对其他人有益,并超出你当前家庭作业的范围。这有意义吗?非常感谢你,克莱,我明白我做错了什么。