Sie sind auf Seite 1von 2

Output based on Strings

Q.No. Questions Output


1. String n="Computer Knowledge";
String m="Computer Applications";
System.out.println(n.substring(0,8).concat(m.substring(9))); ComputerApplications
System.out.println(n.endsWith("e")); true
2. String n="Computer Knowledge";
System.out.println(n.substring(4)); uter Knowledge
System.out.println(n.substring(4,12)); uter Know
3. String a="ABC"; String b="BBC";
System.out.println(a.compareTo(b)); -1
4. String a="CBC"; String b="ABC";
System.out.println(a.compareTo(b)); 2
System.out.println(b.compareTo(a)); -2
5. String a="A"; String b="a";
System.out.println(a.compareTo(b)); -32
System.out.println(b.compareTo(a)); 32
6. String s1="good";
String s2="world matters";
String str1=s2.substring(5).replace('t','n');
System.out.println(s1.concat(str1)); good manners
7. String s="Examination";
int n=s.length();
System.out.println(s.startsWith(s.substring(5,n))); false
System.out.println(s.charAt(2)= =s.charAt(6)); true
8.
String n="Welcome to the World"; String m="of Java";
Error
System.out.println(n.substring(0,8).concat(m.substring(9)));
StringOutofBoundsException
9. String x="Computer"; String y="Applications";
System.out.println(x.substring(1,5)); ompu
System.out.println(x.indexOf(x.charAt(4))); 4
System.out.println(y+x.substring(5)); Applicationster
System.out.println(x.equals(y)); false
10. String x="Good"; String y="Morning";
System.out.println(x+y); GoodMorning
System.out.println(x.compareTo(y)); -6
System.out.println(x.indexOf(x.charAt(2))); 1
System.out.println(x.equals(y));); false
11. String a="Smartphone"; String b="Graphic Art";
String h=a.substring(2,5);
String k=b.substring(8).toUpperCase();
System.out.println(h); art
System.out.println(k.equalsIgnoreCase(h)); true
12. String s="malayalam";
System.out.println(s.indexOf('m')); 0
System.out.println(s.lastIndexOf('m')); 8
13. String str1="great"; String str2="minds";
System.out.println(str1.substring(0,2).concat(str2.substring(1))); grinds
System.out.println("WH"+(str1.substring(2).toUpperCase())); WHEAT
14. String s="one two three";
int pos=s.indexOf('t'); int pos1=s.indexOf('t',7);
System.out.println(pos+" "+pos1); 48
System.out.println("Hello World".lastIndexOf("Hello".charAt(2))); 9
Write Java statements to perform the following tasks
1. Initialise a variable city to store “DELHI”.
Ans: String city=”DELHI”
2. To replace all occurrences of letter ‘m’ by letter ‘M’ in the line of text “master of computer applications”
Ans: System.out.println("master of computer applications".replace('m','M'));

Das könnte Ihnen auch gefallen