OOPS2
OOPS2
(i)
public class LengthExample{
public static void main(String args[]){
String s1="javatpoint";
String s2="python";
System.out.println("string length is: "+s1.length());//10 is the length of javatp
oint string
System.out.println("string length is: "+s2.length());//6 is the length of python
string
}}
return (char)str.codePointAt(index);
// Driver code
int index = 5;
}
public class Demo {
public static void main(String[] args) {
String str = "pqrstuvw";
System.out.println("String: "+str);
// range from 3 to 6
String strRange = str.substring(3, 6);
System.out.println("Substring: "+strRange);
ALGORITHM:
o STEP 1: START
o STEP 2: DEFINE string str = "Great Power".
o STEP 3: DEFINE newstr as StringBuffer object .
o STEP 4: SET i=0. REPEAT STEP 5 to STEP 6 UNTIL i<str.length().
o STEP 5: IF lower-case character encountered then CONVERT them
in upper-case using built-in function
else
IF upper-case character encountered then CONVERT them in lower-
case characters using built-in function.
o STEP 6: i=i+1
o STEP 7: PRINT newstr.
o STEP 8: END
PROGRAM:
if(Character.isLowerCase(str1.charAt(i))) {
newStr.setCharAt(i, Character.toUpperCase(str1.charAt(i)));
else if(Character.isUpperCase(str1.charAt(i))) {
newStr.setCharAt(i, Character.toLowerCase(str1.charAt(i)));
OUTPUT: