Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 24, 2017 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/0a1ad16679b86e9443acf33709efa0f2 to your computer and use it in GitHub Desktop.
Save peter279k/0a1ad16679b86e9443acf33709efa0f2 to your computer and use it in GitHub Desktop.
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