tips calculator


Submit solution

Points: 100
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Java 19, Java 8

題目說明

請輸入顧客餐點總金額及服務費比率(%),計算服務費以及總應付金額,並將結果列印出。

輸入

由鍵盤輸入餐點總金額、服務費比率(%),請以空格隔開。輸入資料順序為先餐點總金額、後服務費比率。

輸出

計算服務費、總應付金額後輸出至螢幕。服務費、總應付金額計算請四捨五入至小數點後一位即可

sample input & output

輸入 輸出
DataSet1 10 12 Service charge:1.2,Total payment:11.2
DataSet2 60 18 Service charge:10.8,Total payment:70.8
DataSet3 105 10 Service charge:10.5,Total payment:115.5

Comments


  • 0
    scu14156135  commented on Oct. 8, 2025, 6:00 p.m.

    import java.util.*; public class hw3_4 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scr = new Scanner(System.in);
        System.out.println("總金額");
        int total=scr.nextInt();
        System.out.println("服務費比率");
        int rate=scr.nextInt();
        double fee = (double)total*rate*0.01;
        double pay= (double)fee+total;
        System.out.println("service charge");
        System.out.printf( "%.1f" , fee);
        System.out.println("payment");
        System.out.printf("%.1f" ,pay);
    }

    }