java - Display output after input -


i've made program asks user number , checks if equal, less or greater random number. siple guessing game. works display output on same line input can't figure out how this.

ok, i've picked number between 1 , 100. first guess? guess 1: 36 < guess 2: 50 > guess 3: 46 correct. hidden number 46. 

this how want like:

guess 1: 36 < guess 2: 50 > guess 3: 46 correct. hidden number 46. 

how do this? cursor moving down after input when use scanner.nextint();

this current code:

while (!iscorrect) {         system.out.print("guess " + guesscount + ":  ");         currentguess = input.nextint();          if (currentguess == randomnumber) {             iscorrect = true;             system.out.println("that correct. hidden number " + randomnumber);         }         else if (currentguess > randomnumber) {             system.out.println(" >");             ++guesscount;         }         else if (currentguess < randomnumber) {             system.out.println(" <");             ++guesscount;         }      } 

if need format output try saving input arraylist, clearing screen, printing previous inputs screen again.

list<integer> foo = new arraylist<integer>();  while (!iscorrect) {     system.out.print("guess " + guesscount + ": ");     guesscount++;     currentguess = input.nextint();     foo.add(currentguess);     for(int = 0; < 50; a++) {         system.out.println('\n');     }     for(int = 0; < foo.size(); i++) {         currentguess = foo.get(i);         system.out.print("guess " + (i+1) + ": " + currentguess);         if (currentguess == randomnumber) {             iscorrect = true;             system.out.println(" correct. hidden number " + randomnumber);         }         else if (currentguess > randomnumber) {             system.out.println(" >");             }         else if (currentguess < randomnumber) {             system.out.println(" <");         }     } } 

to clear screen printed out 50 blank lines.

a solution clear console proposed here: java: clear console however, didn't work me or chris.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -