Created
May 24, 2017 10:46
-
-
Save peter279k/0a1ad16679b86e9443acf33709efa0f2 to your computer and use it in GitHub Desktop.
TQC+ JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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