Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import java.util.*;
  2. public class MainThread {
  3.  
  4. public static void main(String[] args) {
  5. // TODO Auto-generated method stub
  6.  
  7. Scanner answer = new Scanner(System.in);
  8.  
  9. System.out.println("Give me a single character: ");
  10. char h = answer.next().charAt(0);
  11. System.out.println("Give me another single character: ");
  12. char a = answer.next().charAt(0);
  13.  
  14.  
  15. MyThread t1 = new MyThread(h);
  16. MyThread t2 = new MyThread(a);
  17.  
  18. t1.start(h);
  19. t2.start(a);
  20.  
  21.  
  22. answer.close();
  23. }
  24.  
  25. import java.util.*;
  26. public class MyThread extends Thread{
  27.  
  28. Scanner answer = new Scanner(System.in);
  29.  
  30. public MyThread(char x) {
  31. // TODO Auto-generated constructor stub
  32. }
  33.  
  34.  
  35. public void Stored(char x){
  36. System.out.println("Type a single letter here: ");
  37.  
  38.  
  39. }
  40.  
  41.  
  42. //modified run method
  43. public void start(char x){
  44.  
  45. for(int i = 0; i < 1000; i++){
  46. System.out.print(x);
  47. try {
  48. Thread.sleep(1);
  49. } catch (InterruptedException e) {
  50.  
  51. e.printStackTrace();
  52. }
  53. Thread.yield();
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement