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));

Views 10

Answer:

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.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.