+ 2

System.out.print(result) - why not "result"?

When coding an operator, for example +, I had to write: int x =2 , y =4 ; int sum = x + y ; System.out.print(result); why not ....("result") because, we know if we are to print a string of words, the words must be included in " "

12th Nov 2016, 4:32 PM
Hossain Abeer
Hossain Abeer - avatar
12 Answers
+ 6
Your variable 'result' isnt declared. int x=2, y=4; int result = x+y; System.out.println(result); or int x=2, y=4; int sum= x+y; System.out.println("Result: " + sum);
13th Nov 2016, 3:04 PM
Niels Leiner
+ 5
Syastem.out.println("sum");
12th Nov 2016, 5:17 PM
raja
+ 2
System.out.print(”Result: ” + sum);
13th Nov 2016, 6:34 AM
Mista Ben
Mista Ben - avatar
+ 2
"result" will simply print "result", result will print the value of result
13th Nov 2016, 8:09 PM
Chahat Gupta
Chahat Gupta - avatar
+ 2
Dude, your "result" is a string and if you print it, it gives "result". You have to declare that. And here SOP will be (sum) not (result). Thank you.
25th Nov 2016, 2:34 PM
Suryanarayan Behera
Suryanarayan Behera - avatar
+ 2
because here result is a value not a string
27th Dec 2016, 2:47 PM
SAGAR SINGHA ROY
SAGAR SINGHA ROY - avatar
+ 1
result isn't declared so it will shown a error
12th Nov 2016, 4:52 PM
bayram akdemir
bayram akdemir - avatar
+ 1
You need to include this in "", because result variable doesn't exist. How answered previous, it will crush.
12th Nov 2016, 6:22 PM
Adefful
0
1st: sum is the name of your variable 2nd: (sum) but not ("sum") cos' everything in the "" is considered String or as you may realize "text"
1st Dec 2016, 11:25 PM
Marcelo Carvalho
Marcelo Carvalho - avatar
0
We don't "" on numbers 'result' is a value or a number.
21st Dec 2016, 2:57 PM
Abid
Abid - avatar
0
first you declare the variable result
6th Jan 2017, 9:56 AM
Deepan
- 1
java
27th Nov 2016, 10:53 AM
sachin pagariya