style and efficiency are required. YOU WILL NOT GET CREDIT IF YOUR EXAM CANNOT B
ID: 3909844 • Letter: S
Question
style and efficiency are required. YOU WILL NOT GET CREDIT IF YOUR EXAM CANNOT BE READ. NO NOTES, BOOKS, OR CALCULATORS MAY BE USED DURING THIS EXAM. I. (2 points) Convert the following algebraic expression into a valid Java statement. value= +E+ ?? + C C F Il. (8 points, 2 points each) Compute the value of each of the following expressions or write INVALID if the statement is not valid. Be sure to include a decimal point if the result is real. (2 pts each) a. 5+36 b. 15%2+6%3 c. 2/3+ 3*4 d. 18/(6%2)Explanation / Answer
Ans No. 1:
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
double A,B,C,D,E,F; //Declaration of Variable
A = 2; //Assignment of variable
B = 4;
C = 8;
D = 6;
E = 10;
F = 12;
double value = (B / (D + E)) + ((A + C)/(C * F)); //given Expression in java
System.out.println(value); //Printing the output
}
}
Output:
Ans No. 2
a. Output: 23
b. Output: 1.0
c. Output: 12.0
d. Output: Invalid (java.lang.ArithmeticException: / by zero)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.