We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d9af670 commit d2ae4ecCopy full SHA for d2ae4ec
1 file changed
chat.java
@@ -0,0 +1,29 @@
1
+import java.util.Scanner;
2
+
3
+public class Chat {
4
+ public static void main(String[] args) {
5
+ Scanner sc = new Scanner(System.in);
6
7
+ System.out.println("Simple Java Chat App");
8
+ System.out.print("Enter User 1 name: ");
9
+ String user1 = sc.nextLine();
10
11
+ System.out.print("Enter User 2 name: ");
12
+ String user2 = sc.nextLine();
13
14
+ System.out.println("\nType 'exit' to stop chatting\n");
15
16
+ while (true) {
17
+ System.out.print(user1 + ": ");
18
+ String msg1 = sc.nextLine();
19
+ if (msg1.equalsIgnoreCase("exit")) break;
20
21
+ System.out.print(user2 + ": ");
22
+ String msg2 = sc.nextLine();
23
+ if (msg2.equalsIgnoreCase("exit")) break;
24
+ }
25
26
+ System.out.println("Chat ended.");
27
+ sc.close();
28
29
+}
0 commit comments