The result of die variable assignment float x int 3072 is x
Solution
The answer for question no:21 is option B.When we execute float x = (int)36.72; we will get the result as 36.0.Because here comes the concept of typecasting.As float is a higher level than int it gets typecasted to int but vice versa is not possible as it gives a type mismatch exception.Here in this case while the result gets typecasted to int,it will discard anything after the decimal point.
Please give a clear options for the question no:22 as I cannot find any relational operator in that question. I was hoping option C but its showing like !- to me.So please make it clear.
The answer for question no:23 is C) !(x <= 1 || x >= 10) because though the condition is returning the value 2 in x<=1 but it is casted with ! as !(x<=1).
public class SampleMain {
/**
* @param args
*/
public static void main(String[] args) {
int x = 10;
// try with 1 or 10
System.out.println(\"Check in between value 1st:\" + (1 <= x && x <= 10));
System.out.println(\"Check in between value 2nd:\" + (!(x < 1 || 10 < x)));
System.out.println(\"Check in between value 3rd:\" + (!(x <= 1 || x >= 10)));
System.out.println(\"Check in between value 4th:\" + (10 >= x && x >= 1));
System.out.println(\"Check in between value 5th:\" + (!(x > 10) && !(x < 1)));
}
}
The answer for the question no:24 is option A. Because compareTo() returns zero only when both the strings are equal in content wise.So string1 and string2 are equal only when the method compareTo() returns the value zero.
Example for your review:
public class CompareToTestCase {
public static void main(String args[]) {
String s1 = \"hello\";
String s2 = \"hello\";
String s3 = \"mello\";
System.out.println(s1.compareTo(s2));
System.out.println(s1.compareTo(s3));
}
}
The answer for question no:25 is C.Here the substring() method will give the answer an.The substring() method returns new String object containing the substring of the given string from specified parameters.
The first parameter will take starting index as argument and the second parameter will take ending index as second argument.
Hope these answers were helpful...
