TQC+ JAVA 304 餐點費用
import java.util.Scanner;
public class JPA03 {
public static void main(String[] args) {
int total = 0;
int s = 0;
int count = 0;
double average;
Scanner key=new Scanner(System.in);
int n=-1;
while(n==-1){
System.out.print("Please enter meal dollars or enter -1 to stop: ");
s = key.nextInt();
if(s==-1)
break;
else
count++;
total += s;
}
average=(double)total/count;
System.out.println("餐點總費用:"+total);
System.out.printf(" %d 道餐點平均費用為: %.2f %n",count,average);
}
}
沒有留言:
張貼留言