java - adding text after prompt for input -


i'm new java & don't know if i'm trying doable in cmd want know if there's way ask user input while displaying @ right of input, like:

enter weight: _ kg

specifying unit want weight in example

here code sample have far

import java.util.*;  public class scannerprompt {    public static void main(string[] args) {      int[] listofintegers = new int[10];      scanner s = new scanner(system.in);      (int = 0; < 10; i++) {       system.out.print("enter num: ");       int num = s.nextint();       listofintegers[i] = num;     }    } } 

we can use \r in tricky way:

import java.util.scanner;  public class javaapplication2 {   public static void main(string[] args) {         int i=0;         scanner s = new scanner(system.in);         system.out.print("enter num: __kg\r");         system.out.print("enter num: ");         = s.nextint();         system.out.println("\n"+i);          } } 

how works:

  • we print enter num: __kg , \r make cursor @ begining of line
  • now if print something, overwrite fist message because cursor in fist position, overwrite same letters part make cursor @ desired position. hence print enter num:

dont use println because insert \n @ end, , dont test in ide use console of system.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -