2) Run the Java code below and explain why result1/result2 are different and why before/after f value are different regarding operand evaluation order.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question
2) Run the Java code below and explain why result1/result2 are different and why
before/after f value are different regarding operand evaluation order.
public class GlobalMembers
{ public static int b= 4, f= 5;
public static int fun1(int a)
{ a = 17;
b=b+2;
return a;
}
public static int fun2()
{f=f+1;
return f,
}
public static void main(String args[])
{ int a = 6, d= 12, temp;
float result1, result2;
result1 = (fun1 (a) + b)/ (fun1(a) - d);
System.out.print("\n a=" +a +" b="+b+" d=" + d);
System.out.print(" result1="+result1);
temp = fun1(a);
result2 = (temp + b) / (temp - d);
System.out.print("\n a=" + a +" b=" +b +" d=" + d);
System.out.print(" temp="+ temp +"result2="+ result2);
System.out.print("\n before f="+ f);
f=f+ fun20;
System.out.print("\n after f="+ f);
}
}
Transcribed Image Text:2) Run the Java code below and explain why result1/result2 are different and why before/after f value are different regarding operand evaluation order. public class GlobalMembers { public static int b= 4, f= 5; public static int fun1(int a) { a = 17; b=b+2; return a; } public static int fun2() {f=f+1; return f, } public static void main(String args[]) { int a = 6, d= 12, temp; float result1, result2; result1 = (fun1 (a) + b)/ (fun1(a) - d); System.out.print("\n a=" +a +" b="+b+" d=" + d); System.out.print(" result1="+result1); temp = fun1(a); result2 = (temp + b) / (temp - d); System.out.print("\n a=" + a +" b=" +b +" d=" + d); System.out.print(" temp="+ temp +"result2="+ result2); System.out.print("\n before f="+ f); f=f+ fun20; System.out.print("\n after f="+ f); } }
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT