Java While Loops -


i working on while loop stop while variable less 100. have currently, output stops @ 128 - not sure why prints 128 when last output should 64. pointers?

import java.util.scanner;  public class insectgrowth { public static void main (string [] args) {   int numinsects = 0;    numinsects = 8;     system.out.print(numinsects + " ");    while (numinsects < 100) {      numinsects = numinsects * 2;      system.out.print(numinsects + " ");   }    system.out.println();    return;   } } 

the last value printed 128 because execute

numinsects = numinsects * 2; 

before

system.out.print(numinsects + " "); 

therefore loop stops when numinsects 64, multiplies 2 before printing, hence why see 128.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -