Skip to content

Instantly share code, notes, and snippets.

@peter279k peter279k/JPA03.java
Created May 24, 2017

Embed
What would you like to do?
TQC+ JAVA
import java.util.Scanner;
public class JPA03 {
public static void main(String[] args) {
int total = 0;
int s = 0;
int count = 0;
double average = 0.0;
Scanner input = new Scanner(System.in);
System.out.print("Please enter meal dollars or enter -1 to stop: ");
int dollar = input.nextInt();
while(true) {
if(dollar == -1) {
break;
}
count += 1;
total += dollar;
System.out.print("Please enter meal dollars or enter -1 to stop: ");
dollar = input.nextInt();
}
average = (double)total / (double)count;
System.out.println("餐點總費用:" + total);
System.out.printf(" %d 道餐點平均費用為: %.2f \r\n", count, average);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.