java 基礎程式之商場結賬管理

來源:互聯網
上載者:User

標籤:bre   package   out   number   商品   system   boolean   price   continue   

項目流程:所選擇的商品價格和商品數量,每統計一次,計算總價,之後總價進行累加,最後選擇退出或者清空total的記憶體空間。進行下一次的結賬;

package com.zhiyou100;import java.util.Scanner;import java.util.function.Predicate;public class MyShop {public static void main(String[] args) {boolean sc =true;while (sc) {double total=0;Scanner scanner =new Scanner(System.in);    System.out.println("歡迎來到我的商店!");    while (true) {    System.out.print("請輸入單價:");double  price=scanner.nextDouble();System.out.print("請輸入數量:");int number=scanner.nextInt();total+=price*number;        System.out.printf("累計結果:¥:%.2f %n", total);    System.out.println("清零請按c,退出請按q,繼續請按任意鍵");    scanner.nextLine();    String flog=scanner.nextLine();    if (flog.equals("c")) {total=0;}else if (flog.equals("q")) {sc=false;break;}else {continue;//continue 繼續}   }}}}

 

  

 

java 基礎程式之商場結賬管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.