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
2 Respuestas
+ 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
}
}
+ 21
Use System.out.print() instead of println() 😊