Strings
Seoul National University of Science and Technology
Information Technology Management
Lecture slides index
May 10, 2025
magicWord, that contains value "abracadabra".Sample Output
nextLine-method offered by Scanner.Sample Output
+-operator between two strings, you get a new string that’s a combination of those two strings.Sample Output
==.equals-command, which is always appended to the end of the string that we want to compare.equals command is always appended to the end of the string that we want to compare, “string variable dot equals some text”.split-method of the String class.split method returns an array of the resulting sub-parts. and prints each part of the string on a new line.Sample Output
and then prints the pieces that contain av, each on a new line.contains-method, which tells if a string contains another string.Sample Output
csv) format, where commas are used to separate values.Sample Output
and prints the first part of the string.Sample Output
and prints the last part of the string.Sample Output
charAt method.Integer.valueOf())Scanner reader = new Scanner(System.in);
int sum = 0;
int count = 0;
while (true) {
String input = reader.nextLine();
if (input.equals("")) {
break;
}
String[] parts = input.split(",");
sum = sum + Integer.valueOf(parts[1]);
count = count + 1;
}
if (count > 0) {
System.out.println("Age average: " + (1.0 * sum / count));
} else {
System.out.println("No input.");
}Sample Output
Sample Output
length()-method:Sample Output
Sample Output 1

Computer Language