-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
26 lines (18 loc) · 695 Bytes
/
Main.java
File metadata and controls
26 lines (18 loc) · 695 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
package Threading;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
// threading allow program to run multiple task simultaneously
// 1. extend thread class 2. implement runnable interface
Scanner scanner = new Scanner(System.in);
MyRunnable runnable = new MyRunnable();
Thread thread = new Thread(runnable);
thread.setDaemon(true);
thread.start();
System.out.println("You have 5 second to answer this question!");
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.println("Hello " + name);
scanner.close();
}
}