+ 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
9 odpowiedzi
+ 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.
+ 5
From left to right.
* and / have same precedence.
https://www.programiz.com/java-programming/operator-precedence
+ 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.
+ 3
It doesn't matter if u do right to left or left to right.both are same.
+ 1
Even if you go left to right, the answer is 25.
+ 1
I know that both will give same answer Jackson O’Donnell but I need the right procedure
+ 1
answer is 25
0
It's 25 but it must be written as 25.0
0
No Ferdus Mohammed go nd check the linked code