@Test public void whenExchangeMoneyTenThenResultStringWithCoins() { final int moneyToExchange = 10; final String sep = System.getProperty("line.separator"); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { System.setOut(new PrintStream(output)); new CoinsExchange().exchange(moneyToExchange); assertThat(output.toString(), is( String.format("1 1 1 1 1 1 1 1 1 1 %s5 1 1 1 1 1 %s5 5 %s10 %s", sep, sep, sep, sep))); } catch (IOException ioe) { ioe.printStackTrace(); } }
public void exchange(int money) { for (int tens = 0; tens <= (money / coins[2]); tens++) { int moneyWithoutTens = money - tens * coins[2]; for (int fives = 0; fives <= (moneyWithoutTens / coins[1]); fives++) { multiplePrint(coins[2], tens); multiplePrint(coins[1], fives); multiplePrint(coins[0], (moneyWithoutTens - fives * coins[1]) / coins[0]); System.out.println(""); } } }
CoinsExchange { public void exchange(int money) { for (int tens = 0; tens <= (money / coins[2]); tens++) { int moneyWithoutTens = money - tens * coins[2]; for (int fives = 0; fives <= (moneyWithoutTens / coins[1]); fives++) { multiplePrint(coins[2], tens); multiplePrint(coins[1], fives); multiplePrint(coins[0], (moneyWithoutTens - fives * coins[1]) / coins[0]); System.out.println(""); } } } }
CoinsExchange { public void exchange(int money) { for (int tens = 0; tens <= (money / coins[2]); tens++) { int moneyWithoutTens = money - tens * coins[2]; for (int fives = 0; fives <= (moneyWithoutTens / coins[1]); fives++) { multiplePrint(coins[2], tens); multiplePrint(coins[1], fives); multiplePrint(coins[0], (moneyWithoutTens - fives * coins[1]) / coins[0]); System.out.println(""); } } }  }
CoinsExchange { public void exchange(int money) { for (int tens = 0; tens <= (money / coins[2]); tens++) { int moneyWithoutTens = money - tens * coins[2]; for (int fives = 0; fives <= (moneyWithoutTens / coins[1]); fives++) { multiplePrint(coins[2], tens); multiplePrint(coins[1], fives); multiplePrint(coins[0], (moneyWithoutTens - fives * coins[1]) / coins[0]); System.out.println(""); } } }  void exchange(int money); }
CoinsExchange { public void exchange(int money) { for (int tens = 0; tens <= (money / coins[2]); tens++) { int moneyWithoutTens = money - tens * coins[2]; for (int fives = 0; fives <= (moneyWithoutTens / coins[1]); fives++) { multiplePrint(coins[2], tens); multiplePrint(coins[1], fives); multiplePrint(coins[0], (moneyWithoutTens - fives * coins[1]) / coins[0]); System.out.println(""); } } }  void exchange(int money);  }