Using scanner/ placing the elements | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Using scanner/ placing the elements

How can i make the result to be placed imediatelly after text not in a new line? and right there where i put "x=" and "y=" the values i enter will be placed after this two ? https://code.sololearn.com/cZ667RRYjrYm/?ref=app

17th Apr 2017, 11:22 AM
Rareş Daniel
Rareş Daniel - avatar
2 Answers
+ 3
First request the input and then use the variable that stored the input to output it with your string too. import java.util.Scanner; class Donuts // Donuts is a random name i had given to the class { public static void main(String[] args) { Scanner storm = new Scanner (System.in); double x, y, z; x=storm.nextDouble(); System.out.println("x=" + x); y=storm.nextDouble(); System.out.println("y=" + y); z=x+y; System.out.print("x+y=" + z); System.out.println(z); // Storm is also a random name but for scanner // Double enters the number with decimals System.out.println("Sum of two numbers"); System.out.println("a=2"); System.out.println("b=1"); System.out.println ("a+b="); int a, b; b=2; a=1; int sum=a+b; System.out.println(sum); // Two kind of exercices } }
17th Apr 2017, 11:34 AM
Ghauth Christians
Ghauth Christians - avatar
+ 21
Use System.out.print() instead of println() 😊
17th Apr 2017, 11:24 AM
Shamima Yasmin
Shamima Yasmin - avatar