Skip to content
Advertisement

How can I shorten many while loops?

This is one of my first attempts to use Java and I tried my best, but I need to shorten it so it’s not so long.

Important is that it keeps all the coins of the Euro. It’s a German code so geld means money.

This part of the code System.out.println(rgeldt + " mal 2 Euro"); just means how often the 2 euros have to be ejected.

JavaScript

Advertisement

Answer

You can put it into a own function:

JavaScript

BTW: By convention, method names in java should start with lower case character

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement