Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Cast product to <code>double</code> value, i.e.: <code>int svar1 = (int)(dollar * valuta);</code>, but then you lose fraction part. Better approach is to declare <code>svar1</code> as <code>double</code>: <code>double svar1 = dollar * valuta</code>. Then, when you open message dialog, you need to properly construct message string. So, if you want to concatenate different factors into one string, you need to use <code>+</code> operator (and you have to make sure, that at least one of those factors is actually a string). So you need:</p> <blockquote> <p><code>showMessageDialog(null, dollar + " * " + valuta + " = " + svar1 + "\n");</code></p> </blockquote> <p>But if you want to have more control over format, you should consider using <code>format</code> method of <code>String</code> class (since 1.5; <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#format%28java.lang.String,%20java.lang.Object...%29" rel="nofollow">see javadoc for String.format explanation</a>). Eventually you can use this:</p> <blockquote> <p><code>showMessageDialog(null, String.format("%0.2f * %0.2f = %0.2f\n", dollar, valuta, svar1));</code></p> </blockquote> <hr> <p>Well, you actually ask for something else now. Okay, see this (with an example of use):</p> <pre><code>private static final int[] PAYMENT_UNITS = { 1000, 500, 200, 100, 50, 20, 10, 5, 1 }; public static void main(final String[] args) { printCashOut(split(2004307)); } private static final void printCashOut(final int[] cacheOut) { int total = 0; for (int i = 0; i &lt; PAYMENT_UNITS.length; i++) { final int p = cacheOut[i] * PAYMENT_UNITS[i]; System.out.printf("%4d x %4d = %8d\n", cacheOut[i], PAYMENT_UNITS[i], p ); total += p; } System.out.printf(" TOTAL: %8d\n", total); } private static final int[] split(final int amount) { if (amount &lt; 0) { return null; } final int[] cashOut = new int[PAYMENT_UNITS.length]; int rest = amount; for (int i = 0; i &lt; PAYMENT_UNITS.length; i++) { cashOut[i] = rest / PAYMENT_UNITS[i]; rest -= cashOut[i] * PAYMENT_UNITS[i]; } return cashOut; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload