本文介绍了打印所有的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我吗?我怎样才能打印所有我会利用的项目? )

pre $ public $ {
$ public $ {
$ (System.in);
字符串选择;
String want =;
双重价格,总数= 0,付款,变更;

System.out.println(Beauty Zone Salon);
System.out.println(欢迎客户);
System.out.println(Hair Cut ...... 100);
System.out.println(Manicure ...... 200);
System.out.println(Pedicure ...... 300);

do {
System.out.print(Enter your choice:);
choice = input.nextLine();
if(choice.equalsIgnoreCase(Haircut)){
System.out.println(You choose Haircut);
价格= 100;
total = total + price;
System.out.print(你想要做另一个服务?);
want = input.nextLine();

} else if(choice.equalsIgnoreCase(Manicure)){
System.out.println(You choose Manicure);
价格= 200;
total = total + price;
System.out.print(你想要做另一个服务?);
want = input.nextLine(); (Pedicure)){
System.out.println(您选择Pedicure);

} else if(choice.equalsIgnoreCase(Pedicure))
价格= 300;
total = total + price;
System.out.print(你想要做另一个服务?);
want = input.nextLine();
}
} while(want.equalsIgnoreCase(Y));
System.out.println(ITEMS \\\
);
System.out.println(总计到期日+总计);
System.out.print(输入您的付款金额:);
payment = input.nextDouble();
change =付款 - 总计;

System.out.println(您的更改是:+更改);
System.out.println(Goodbye);


解决方案

如果您不知道数组,但是可以在循环完成之后构建要打印的所有项目。在开始时:

 字符串items_ordered =; 

然后对于每次购买,当您通过循环时,添加到字符串:

  items_ordered + =理发... 100 \\\

最后打印字符串

  System.out.println(items_ordered) ; 

我想这就是你要求的...

Can someone please help me? How can I print all the items I will avail? Thank you in advance :)

public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String choice;
        String want = "";
        double price, total = 0, payment, change;

        System.out.println("Beauty Zone Salon");
        System.out.println("Welcome Customer");
        System.out.println("Hair Cut......100");
        System.out.println("Manicure......200");
        System.out.println("Pedicure......300");

        do {
            System.out.print("Enter your choice: ");
            choice = input.nextLine();
            if (choice.equalsIgnoreCase("Haircut")) {
                System.out.println("You choose Haircut");
                price = 100;
                total = total + price;
                System.out.print("Do you want to do another service?");
                want = input.nextLine();

            } else if (choice.equalsIgnoreCase("Manicure")) {
                System.out.println("You choose Manicure");
                price = 200;
                total = total + price;
                System.out.print("Do you want to do another service?");
                want = input.nextLine();

            } else if (choice.equalsIgnoreCase("Pedicure")) {
                System.out.println("You choose Pedicure");
                price = 300;
                total = total + price;
                System.out.print("Do you want to do another service?");
                want = input.nextLine();
            }
        } while (want.equalsIgnoreCase("Y"));
        System.out.println("ITEMS\n");
        System.out.println("Your total due is " + total);
        System.out.print("Enter amount of your payment:");
        payment = input.nextDouble();
        change = payment - total;

        System.out.println("Your change is: " + change);
        System.out.println("Goodbye");
    }
解决方案

If you don't know arrays yet, you can build up all the items in a string to be printed after the loop completes. At the beginning:

String items_ordered="";

Then for each purchase, when you go through the loop, add to the string:

items_ordered+="Haircut... 100\n"

At the end, print the string

System.out.println(items_ordered);

I think this is what you are asking...

这篇关于打印所有的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:53