Java For Kids (and grown-ups): Learn to code and create your own projects with Java 8 by Nadia Ameziane Garcia

Java For Kids (and grown-ups): Learn to code and create your own projects with Java 8 by Nadia Ameziane Garcia

Author:Nadia Ameziane Garcia [Ameziane Garcia, Nadia]
Language: eng
Format: azw3
Published: 2017-12-08T16:00:00+00:00


while (enteredNumber >= 1) {

enteredNumber = enteredNumber / 2;

counter++;

}

System.out.println(“It can be divided ”+ counter + “ times.”);

There were other ways to do that, as usual. For instance, coding a while statement that keeps on looping as long as enteredNumber can be divided by 2 without residue. You can code that condition using the module operator.

DO-WHILE

The Do-While statement is very similar to the plain While, the difference is that, with this one, first the code block is ran and then the condition is evaluated.

This means that, whatever the value of the variable is, the code almost runs at least once.



Loading...
Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.