+ 2

What will be the output ???

System.out.print(5*25/5); Please suggest me what is the output.... https://code.sololearn.com/cMMVrwiblIp3/?ref=a According to sololearn output is 25 but my computer teacher told me to follow left to right approach (solving first what appears in left ) Which approach is right and universal

24th Jun 2019, 3:02 PM
Ayush Pandey
Ayush Pandey - avatar
9 Respuestas
+ 2
You should use parentheses to perform any operation first if you do't want to use parentheses then follow left to right approche according to stack infix expression: (a*b/c) process to postfix: 1. (ab/c*) 2. (abc*/) 3. abc*/ when computer solves this postfix expression then the first operator is * and second is /,in the infix expression * is also first operator.
6th Aug 2019, 3:24 PM
Romesh Kumar Tripathi
Romesh Kumar Tripathi - avatar
+ 5
From left to right. * and / have same precedence. https://www.programiz.com/java-programming/operator-precedence
24th Jun 2019, 6:19 PM
Denise Roßberg
Denise Roßberg - avatar
+ 4
It does not matter if you first calc 5 * 25 and then 125/5 or if you first calc 25/5 and then 5 * 5. 5 + 25/5 -> first division then addition output: 10 5 - 25 * 5 -> first multiplication then substraction output: -120 It follows the math rules.
24th Jun 2019, 4:20 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
It doesn't matter if u do right to left or left to right.both are same.
15th Aug 2019, 10:49 AM
Alphin Davis Pomy
Alphin Davis Pomy - avatar
+ 1
Even if you go left to right, the answer is 25.
24th Jun 2019, 3:17 PM
Jackson O’Donnell
+ 1
I know that both will give same answer Jackson O’Donnell but I need the right procedure
24th Jun 2019, 4:57 PM
Ayush Pandey
Ayush Pandey - avatar
+ 1
answer is 25
15th Jul 2019, 1:27 PM
Sakthi Sakthivel
Sakthi Sakthivel - avatar
0
It's 25 but it must be written as 25.0
8th Jul 2019, 11:57 PM
Ferdus Mohammed
Ferdus Mohammed - avatar
0
No Ferdus Mohammed go nd check the linked code
9th Jul 2019, 12:14 AM
Ayush Pandey
Ayush Pandey - avatar