-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcatenate.java
More file actions
44 lines (28 loc) · 1.08 KB
/
Copy pathConcatenate.java
File metadata and controls
44 lines (28 loc) · 1.08 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
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
public class Concatenation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try {
System.out.println("Enter the first string:");
String a = sc.nextLine();
if (a.trim().isEmpty()) {
System.out.println("Error: First string cannot be empty.");
return;
}
System.out.println("Enter the second string:");
String b = sc.nextLine();
if (b.trim().isEmpty()) {
System.out.println("Error: Second string cannot be empty.");
return;
}
String c = a + " " + b;
System.out.println("Concatenated string: " + c);
} catch (Exception e) {
System.out.println("An unexpected error occurred: " + e.getMessage());
} finally {
if (sc != null) {
sc.close();
}
}
}
}