Skip to content

Instantly share code, notes, and snippets.

@peter279k
Last active May 21, 2017 16:42
Show Gist options
  • Save peter279k/b042051a843c486b2c5029a91406af1d to your computer and use it in GitHub Desktop.
Save peter279k/b042051a843c486b2c5029a91406af1d to your computer and use it in GitHub Desktop.
TQC+ JAVA
import java.util.Scanner;
public class JPA01 {
public static void main(String []args) {
Scanner input = new Scanner(System.in);
System.out.print("請輸入您的姓名:");
String name = input.nextLine();
System.out.println("Hi, " + name + ",請輸入您的銅板個數:");
System.out.print("請輸入1元的數量:");
int numOne = input.nextInt();
System.out.print("請輸入5元的數量:");
int numFive = input.nextInt();
System.out.print("請輸入10元的數量:");
int numTen = input.nextInt();
System.out.print("請輸入50元的數量:");
int numFifty = input.nextInt();
int sum = 1 * numOne + 5 * numFive + 10 * numTen + 50 * numFifty;
int thousand = sum / 1000;
sum -= thousand * 1000;
int hundred = sum / 100;
sum -= hundred * 100;
int ten = sum / 10;
sum -= ten * 10;
int dollar = sum;
System.out.println("您的錢總共有:" + thousand + " 千 " + hundred + " 百 " + ten + " 十 " + dollar + " 元");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment