-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathClassB.java
More file actions
31 lines (25 loc) · 1.11 KB
/
ClassB.java
File metadata and controls
31 lines (25 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.engflow.internship.cycleexample.class_b;
import com.engflow.internship.cycleexample.class_c.ClassC;
import com.engflow.internship.cycleexample.interface_b.InterfaceB;
public class ClassB implements InterfaceB {
private ClassC classC;
public ClassB(ClassC classC) {
this.classC = classC;
}
@Override
public void methodB(String input) {
// If the input is null or empty, return immediately
if (input == null || input.isEmpty()) {
return;
}
//Find the index of the first space character in the input string.
int spaceIndex = input.indexOf(' ');
//Extract the word from the beginning of the input string up to the space character.
String word = (spaceIndex == -1) ? input : input.substring(0, spaceIndex);
//Extract the remaining part of the input string after the space character.
String remaining = (spaceIndex == -1) ? "" : input.substring(spaceIndex + 1);
//Print the word extracted from the input string.
System.out.println("ClassB: " + word);
classC.methodA(remaining);
}
}