2016-09-30 8 views
0

Gewünscht:Wie drucke ich auf einer vorherigen Zeile in Java?

Die erste Koordinate ist (input1, input2).

Was ich dir:

Die erste Koordinate (input1

, input2

).

Der Code, den ich verwendet:

Scanner Narwhal = new Scanner(System.in); 

System.out.print("The first coordinate value is ("); 
double x = Narwhal.nextDouble(); 
System.out.print(", "); 
double y = Narwhal.nextDouble(); 
System.out.print(")."); 

Dank!

+0

Sie mischen Eingang und Ausgang, und Sie haben Ihre Eingaben mit validiert ... Oder? –

+0

Ihre Eingabe ist mit Ihrer Ausgabe gemischt. Tun Sie das eine, dann das andere, wenn Sie nicht wollen, dass sie gemischt werden, –

Antwort

2

drucken es auf einmal System.out.printf mit aus. Dies setzt voraus, dass Sie die Aufrufe vor Ihre Druckanweisung verschoben haben.

System.out.printf("The first coordinate value is (%0.1f, %0.1f).", x, y); 
1

Zuerst müssen Sie die Werte von einer Benutzereingabe erhalten und danach sollten Sie drucken. Sie mischen Eingang und Ausgang.

Sie brauchen etwas wie folgt aus:

Scanner Narwhal = new Scanner(System.in); 

double x = Narwhal.nextDouble(); 
double y = Narwhal.nextDouble(); 

System.out.print("The first coordinate value is (" + x); 
System.out.print(", " + y); 
System.out.print(")."); 
0

Sie nicht die Variablen gedruckt wurde:

System.out.print("The first coordinate value is ("); 
double x = Narwhal.nextDouble(); 
System.out.print(x + ", "); 
double y = Narwhal.nextDouble(); 
System.out.print(y + ")."); 
Verwandte Themen