I have an exercise : Accept operator(+, / , * , -)
Example :
I type 5 + 3 this result is = 8.
I have a problem when I print result :
5 + 3
= 8
"= 8" is not same line with 5 + 3.
Can you help me with this problem? Thanks for reading.

Recommended Answers

All 4 Replies

Could you post your actual code
sure that
int x = 5 + 3;
x will be == 8

Could you post your actual code
sure that
int x = 5 + 3;
x will be == 8

I want to ask about format not result.

int a = 5;
int b = 3;
int c = a + b;
System.out.println(a + "+" + b + "=" + c);

If your print out reads:
5+3
=8
Then you must not be printing everything in the same statement.

If this was your intention, then using System.out.print instead of System.out.println on your first print will allow your second print to be on the same line.

If it wasn't your intention, then just do as pbl suggested.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.