Home / Questions / State the value of characteristic and mantissa when the following code is executed: String s = "4.3756"; int n = s.indexOf('.'); int characteristic=Integer.parseInt(s.substring(0,n)); int mantissa=Integer.valueOf(s.substring(n+1));
Explanatory Question

State the value of characteristic and mantissa when the following code is executed:

String s = "4.3756";
int n = s.indexOf('.');
int characteristic=Integer.parseInt(s.substring(0,n));
int mantissa=Integer.valueOf(s.substring(n+1));

👁 106 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

The value of characteristic is 4 and mantissa is 3756.

Index of . in String s is 1 so variable n is initialized to 1. s.substring(0,n) gives 4. Integer.parseInt() converts string "4" into integer 4 and this 4 is assigned to the variable characteristic.

s.substring(n+1) gives 3756 i.e. the string starting at index 2 till the end of s. Integer.valueOf() converts string "3756" into integer 3756 and this value is assigned to the variable mantissa.