※J.Y Chen 的個人部落格 ※

Just Follow Our Heart And We will shine!

149 瀏覽人次

【程式語言】JAVA的第三堂課 |找錢系統 make change money

Published: in JAVA by .

import java.util.Scanner; 

public class ch4
{

  public static void main(String[] arg)
  {
	int money , fifty , ten , five , one;
	Scanner scn= new Scanner(System.in);
	System.out.print("Input the amount for change:");
	money = scn.nextInt();
	fifty = money / 50;
	ten = (money - (50*fifty))/10;
	five = (money - ((50*fifty) + (10*ten)))/5;
	one = (money - ((50*fifty) + (10*ten) + (five*5)));
	System.out.println("50's:" + fifty);
	System.out.println("10's:" + ten);
	System.out.println("5's:" + five);
	System.out.println("1's:" + one);
  }
 
}
©2019 - 2024 Henry Chen