JAVA PROGRAMMING Suppose that s1, s2, and s3 are three strings, given as follows
ID: 673642 • Letter: J
Question
JAVA PROGRAMMING
Suppose that s1, s2, and s3 are three strings, given as follows String s1 = "Welcome to Java". String s2 = "Programming is fun". String s3- "Welcome to Java" hat are the results of the following expressions? (a) s1 = s2 (b) s2 =-33 (c) s1.equals(s2) (d) s1.equals(s3) (e) s1.compare To(s2) (f) s2.compareTo(s3) (g) s2.compareTo(s2) (h) s1.charAt(0) (i) s1.indexOf(j') (j) s1.indexOf("to") (k) s1.lastlndexOf('a') (I) s1.lastlndexOf("o", 15) (m) s1.length() (n) s1.substring(5) (o) s1.substring(5, 11) (p) s1.startsWith("Wel") (q) s1.endsWith("Java") (r) s1.toLowerCase() (s) s1.toUpperCase() (t) s1.concat(s2) (u) s1.contains(s2) (v)" Wel ".trim)Explanation / Answer
Answers :
(a) false
(b) false
(c) false
(d) true
(e) 7
(f) -7
(g) 0
(h) W
(i) -1
(j) 8
(k) 14
(l) 9
(m) 15
(n) me to Java
(O) me to
(p) true
(q) true
(r) welcome to java
(s) WELCOME TO JAVA
(t) Welcome to JavaProgramming is fun
(u) false
(v) Wel
Java Program:
public class CompareTo {
public static void main(String args[]){
String s1 ="Welcome to Java";
String s2 = "Programming is fun";
String s3 = "Welcome to Java";
System.out.println(s1 == s2);
System.out.println(s2 == s3);
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s3));
System.out.println(s1.compareTo(s2));
System.out.println(s2.compareTo(s3));
System.out.println(s2.compareTo(s2));
System.out.println(s1.charAt(0));
System.out.println(s1.indexOf('j'));
System.out.println(s1.indexOf("to"));
System.out.println(s1.lastIndexOf('a'));
System.out.println(s1.lastIndexOf("o",15));
System.out.println(s1.length());
System.out.println(s1.substring(5));
System.out.println(s1.substring(5,11));
System.out.println(s1.startsWith("Wel"));
System.out.println(s1.endsWith("Java"));
System.out.println(s1.toLowerCase());
System.out.println(s1.toUpperCase());
System.out.println(s1.concat(s2));
System.out.println(s1.contains(s2));
System.out.println(" Wel ".trim());
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.