-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.java
More file actions
29 lines (22 loc) · 815 Bytes
/
chat.java
File metadata and controls
29 lines (22 loc) · 815 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
25
26
27
28
29
import java.util.Scanner;
public class Chat {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Simple Java Chat App");
System.out.print("Enter User 1 name: ");
String user1 = sc.nextLine();
System.out.print("Enter User 2 name: ");
String user2 = sc.nextLine();
System.out.println("\nType 'exit' to stop chatting\n");
while (true) {
System.out.print(user1 + ": ");
String msg1 = sc.nextLine();
if (msg1.equalsIgnoreCase("exit")) break;
System.out.print(user2 + ": ");
String msg2 = sc.nextLine();
if (msg2.equalsIgnoreCase("exit")) break;
}
System.out.println("Chat ended.");
sc.close();
}
}