java - Reading input data using Scanner class -


i have doubt on reading input using scanner class. goes way.if use print instead of println can input in same line

public class {     public static void main(string[] args) {         scanner sc = new scanner(system.in);         system.out.print("enter loan amount:   ");         double loanamount = sc.nextdouble();     } } 

now want extend use of scanner in other way unable so.

public class {     public static void main(string[] args) {         scanner sc = new scanner(system.in);         string input = "";         double val = 0.0;         system.out.println(""enter command push n,add");         calculator xyz = new calculator();         while(true) {             input = sc.next();             if(input.equals("push")+val) {                val = sc.nextdouble();                 xyz.push(val);                 abc.getvalues();             }             if(input.equals("add"))             xyz.add();          }     } } 

in above want read value in same line after type "push" eg., when run above code o/p follows

enter command  push 4 4.0 

but want o/p as:

enter command  push 4 4.0 

try :-

public class a{     public static void main(string[] args) {    scanner sc = new scanner(system.in);     system.out.println("enter command");    while(true){     string val[]=sc.nextline().split(" ");     //system.out.println("push "+val[1]);     system.out.println(double.parsedouble(val[1]));  }    }    } 

output :-

enter command push 4 4.0 push 5 5.0 push 6 6.0 

hope you.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -