Select the correct answerAssuming that the required imports are done, what will be the output of the following Java code snippet?public class AddDemo { public static void main(String args[]) { BigDecimal b = new BigDecimal("23.43"); BigDecimal br = new BigDecimal("24"); BigDecimal bres = b.add(new BigDecimal("450.23")); System.out.println("Add: "+bres); MathContext mc = new MathContext(2, RoundingMode.DOWN); BigDecimal bdecMath = b.add(new BigDecimal("450.23"), mc); System.out.println("Add using MathContext: "+bdecMath); }}OptionsAdd: 473.66Add using MathContext: 4.7E+2Add: 450.66Add using MathContext: 4.5E+2Add 4.7E+2Add using MathContext: 473.66Runtime exception
Question
Select the correct answerAssuming that the required imports are done, what will be the output of the following Java code snippet?public class AddDemo { public static void main(String args[]) { BigDecimal b = new BigDecimal("23.43"); BigDecimal br = new BigDecimal("24"); BigDecimal bres = b.add(new BigDecimal("450.23")); System.out.println("Add: "+bres); MathContext mc = new MathContext(2, RoundingMode.DOWN); BigDecimal bdecMath = b.add(new BigDecimal("450.23"), mc); System.out.println("Add using MathContext: "+bdecMath); }}OptionsAdd: 473.66Add using MathContext: 4.7E+2Add: 450.66Add using MathContext: 4.5E+2Add 4.7E+2Add using MathContext: 473.66Runtime exception
Solution
The correct answer is:
Add: 473.66 Add using MathContext: 4.7E+2
Similar Questions
Select the correct answerAssuming that the required imports are done, what will be the output of the following Java program?class string_class { public static void main(String args[]) { String obj = "I LIKE CODETANTRA"; System.out.println(obj.length()); }}Options1116917
Select the correct answerAssuming that the required imports are done, what will be the output of the following Java code?class rectangle { int width; int length; int area; void area() { area = width*length; System.out.println(area); }} class Output { public static void main(String args[]) { rectangle obj = new rectangle(); obj.width=5; obj.length=6; obj.area(); }}Options1301136
Select the correct answerAssuming that all the necessary imports are done, what will be the output of the following Java code? class codetantra { public int a; public int b; codetantra() { a = 5; b = 6; } } class coding extends codetantra { int i; coding() { super(); } } class inheritance { public static void main(String args[]) { coding obj = new coding(); System.out.println(obj.a + " " + obj.b); } }Options6 55 6Runtime ErrorCompilation Error
Select the correct answerAssuming that all the necessary imports are done, what will be the output of the following Java code? class parent { int x; void display() { System.out.println(x); } } class child extends parent { int y; void display() { System.out.println(y); } } class method_overriding { public static void main(String args[]) { child obj = new child(); obj.x=4; obj.y=5; obj.display(); } }Options435Compilation Error
Select the correct answerWhat will be the output of the following Java program?class Output { public static void main(String args[]) { double ct1 = 2.5; double ct2 = 3.5; double ct3 = Math.max( ct1, ct2 ); System.out.print(ct3); } }Optionsfalsetrue2.53.5
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.