Computer Applications
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));
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 Questions
String s1 = "45.50"; String s2 = "54.50"; double d1=Double.parseDouble(s1); double d2=Double.parseDouble(s2); int x= (int)(d1+d2);What is value of x?
Primitive data types are built in data types which are a part of the wrapper classes. These wrapper classes are encapsulated in the java.lang package. Non primitive datatypes like Scanner class are a part of the utility package for which an object needs to be created.
(a) To which package the Character and Boolean classes belong?
(b) Write the statement to access the Scanner class in the program.
Give the output of the following code:
String P = "20", Q ="19"; int a = Integer.parseInt(P); int b = Integer.valueOf(Q); System.out.println(a+""+b);