-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst.java
More file actions
24 lines (17 loc) · 714 Bytes
/
first.java
File metadata and controls
24 lines (17 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package Chalanges;
public class first {
public static String concatenateStrings(String ...strings) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < strings.length; i++) {
result.append(strings[i]);
if (i < strings.length - 1 && !strings[i+1].matches("[.!?,]")) {
result.append(" "); // Add space between strings
}
}
return result.toString();
}
public static void main(String[] args) {
String result = concatenateStrings("Hello", "World", "!", "Welcome", "to", "Java", ".");
System.out.println(result);
}
}