Java - sc.nextDouble() - make another line

Sorry for my English but it is not my native language. I have to create program to calculate some math equations. And I have find little annoying problem. I need to get my input number in one line, but when i use

sc = new Scanner(System.in);        
sc.useLocale(Locale.US);

System.out.print("a=");
double a = sc.nextDouble();

System.out.print(", b=");
double b = sc.nextDouble();

I get something like this:

a=Some Number
, b=Some Number

But I need this(to be an the same line):

a=Some Number, b=Some Number

I have tried to find the answer but after 4 hours I can't find it or I don't understand it. Thanks for help.

Upvotes: 0

Views: 259

Answers (3)

kaustubhd9
kaustubhd9

Reputation: 139

Scanner sc = new Scanner(System.in);        
sc.useLocale(Locale.US);
double a = sc.nextDouble();
double b = sc.nextDouble();
System.out.println("a="+a+"b="+b);

Upvotes: 1

Engrtunze
Engrtunze

Reputation: 30

double a = sc.nextDouble();
double a = sc.nextDouble();
 System.out.print("a ="+ a + ","+ "b ="+b );

Upvotes: 1

Marvin Klar
Marvin Klar

Reputation: 1917

You would do so:

double a = sc.nextDouble();
double b = sc.nextDouble();
System.out.print("a=" + a + ",b=" + b);

Upvotes: 1

Related Questions