Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package collatz;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author Teodoras Antanas Stefanovicius KM1
  13. */
  14.  
  15. class ThreadCollatz extends Thread {
  16. private Thread t;
  17. public int a, b;
  18. public long[] list;
  19.  
  20. ThreadCollatz(int x, int y, long[] listC){
  21. a = x;
  22. b = y;
  23. list = listC;
  24. }
  25.  
  26. public void run(){
  27. try{
  28. CollatzMethod collatzmethod = new CollatzMethod();
  29. collatzmethod.findSequence(a,b,list);
  30. }catch(Exception e){
  31. System.out.println("Thread interrupted.");
  32. }
  33. }
  34.  
  35. public void start(){
  36. System.out.println("Thread Started");
  37. if (t == null){
  38. t = new Thread();
  39. t.start();
  40. }
  41. }
  42. }
  43.  
  44. public class Collatz{
  45.  
  46. public static void main(String[] args) {
  47.  
  48. /*Input*/
  49. Scanner keyboard = new Scanner(System.in);
  50. System.out.print("Enter two integer numbers:\n");
  51. int a = keyboard.nextInt();
  52. int b = keyboard.nextInt();
  53. long[] list = new long[10000];
  54. System.out.print("Array: ");
  55.  
  56. /*Method*/
  57. long startTime = System.currentTimeMillis();
  58.  
  59. ThreadCollatz T1 = new ThreadCollatz(a,b,list);
  60. T1.start();
  61.  
  62. /*Collatz T2 = new Collatz(a,b,list);
  63. T2.start();*/
  64.  
  65. //collatzmethod.findSequence(a,b,list);
  66.  
  67. long endTime = System.currentTimeMillis();
  68.  
  69. /*Output*/
  70.  
  71. System.out.println("That took " + (endTime - startTime) + " milliseconds");
  72.  
  73.  
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement