返回列表 發帖
  1. import java.util.Scanner;
  2. public class JPA03
  3. {
  4.         static Scanner num=new Scanner(System.in);
  5.     public static void main(String[] args) {
  6.         int total = 0;
  7.         int s = 0;
  8.         int count = 0;
  9.         double average;
  10.         
  11.         
  12.         while(true)
  13.         {
  14.                 System.out.print("Please enter meal dollars or enter -1 to stop: ");
  15.             s=num.nextInt();
  16.             if(s==-1)
  17.             {
  18.                     break;
  19.             }
  20.             total+=s;
  21.             count++;
  22.             
  23.         }
  24.         average=total/count;
  25.         System.out.printf("餐點總費用:",total);
  26.         System.out.printf(" %d 道餐點平均費用為: %.2f %n",average);
  27.         }
  28.         
  29.     }
複製代碼

TOP

返回列表