Test5.java(java homework)

來源:互聯網
上載者:User

4  設有各不相同面值的人民幣若干,編寫一個電腦程式,對任意輸入的一個金額,給出能夠組合出這個值得最佳可能,要求使用幣值的個數最少。

import java.util.*;<br />public class Test5 {<br />public static void main (String[] args) {<br />//10, 5, 2, 1;<br />System.out.println("Input money:");<br />Scanner in = new Scanner(System.in);<br /> int m = in.nextInt();<br />int n10 = m / 10;<br />m %= 10;<br />int n5 = m / 5;<br />m %= 5;<br />int n2 = m / 2;<br />m %= 2;<br />int n1 = m;<br />System.out.println("m=" + "10*" + n10 + "+5*" + n5 +"+2*" + n2 + "+1*" + n1 );<br />}<br />}<br />

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.