Computer Applications
Give the output of the following:
String n = "Computer Knowledge";
String m = "Computer Applications";
System.out.println(n.substring(0,8).concat(m.substring(9)));
System.out.println(n.endsWith("e"));
Answer
ComputerApplications
true
Working
n.substring(0,8)
returns the substring of n starting at index 0 till 7 (i.e. 8 - 1 = 7) which is "Computer". m.substring(9)
returns the substring of m starting at index 9 till the end of the string which is "Applications". concat() method joins "Computer" and "Applications" together to give the output as ComputerApplications.
Related Questions
If:
String x = "Computer";
String y = "Applications";
What do the following function returns?
System.out.println(x.equals(y));Give the output of the following statements:
String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
System.out.println(x[3].length());
Give the output of the following statements:
String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
System.out.println(x[1]);
If:
String x = "Computer";
String y = "Applications";
What do the following function returns?
System.out.println(y + x.substring(5));