-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathClassA.java
More file actions
31 lines (25 loc) · 1.07 KB
/
ClassA.java
File metadata and controls
31 lines (25 loc) · 1.07 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.cycleexample.class_a;
import com.engflow.cycleexample.class_b.ClassB;
import com.engflow.cycleexample.interface_a.InterfaceA;
public class ClassA implements InterfaceA {
private ClassB classB;
public ClassA(ClassB classB) {
this.classB = classB;
}
@Override
public void methodA(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("ClassA: " + word);
classB.methodB(remaining);
}
}