Lab 1 - String
Lab 1 - String
String t = buf.toString();
System.out.println(“sub” + t.substring(2,7));
t = buf.append(t.substring(0,7) + “i”);
System.out.println(t);
t = buf.reverse();
System.out.println(buf);
}
}
Example
String text1 = “JAVA”; Output:
int n = 55;
String text = “programming”;
System.out.println(“This string is “ + text);
System.out.println(text.length());
System.out.println(“The character in index 4 is “ + text.charAt(4));
System.out.println(“The index of character g is “ +
test.indexOf(‘g’));
System.out.println(text.toLowerCase());
System.out.println(text.toUpperCase());
System.out.println(text.substring(3,7));
System.out.println(text.substring(3,7).length());
text1 += text;
System.out.println(text1);
System.out.println(text1.indexOf(‘r’, text1.indexOf(‘r’) + 1));
System.out.println(text.lastIndexOf(‘m’));
System.out.println(text1.replace(‘A’, ‘O’));
String strN = String.valueOf(n);
Exercise 1
Write and run a Java program that does the following task:
Tasks Codes
1. Declare a String object named s containing the string
“Show me the meaning of being lonely”
Sample:
Sample:
Extra task:
Ask the user to input 3 names (store in an array) then show the last names is
beginning with 'C'