- import java.util.Scanner;
- public class hi87 {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- Scanner k = new Scanner(System.in);
-
- int a=0;
- int b=0;
- int c=0;
-
- double average;
- while(true)
- {
- System.out.print("Please enter meal dollars or enter -1 to stop: ");
- a=k.nextInt();
- if(a==-1)
- {
- break;
- }
- else
- {
- b=b+a;
- c++;
- }
- }
- average=b/c;
- System.out.println("餐點總費用:"+b);
- System.out.printf(" %d 道餐點平均費用為: %.2f \n",c,average);
- }
-
- }
-
複製代碼 |