Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package collatz;
- import java.util.Scanner;
- /**
- *
- * @author Teodoras Antanas Stefanovicius KM1
- */
- class ThreadCollatz extends Thread {
- private Thread t;
- public int a, b;
- public long[] list;
- ThreadCollatz(int x, int y, long[] listC){
- a = x;
- b = y;
- list = listC;
- }
- public void run(){
- try{
- CollatzMethod collatzmethod = new CollatzMethod();
- collatzmethod.findSequence(a,b,list);
- }catch(Exception e){
- System.out.println("Thread interrupted.");
- }
- }
- public void start(){
- System.out.println("Thread Started");
- if (t == null){
- t = new Thread();
- t.start();
- }
- }
- }
- public class Collatz{
- public static void main(String[] args) {
- /*Input*/
- Scanner keyboard = new Scanner(System.in);
- System.out.print("Enter two integer numbers:\n");
- int a = keyboard.nextInt();
- int b = keyboard.nextInt();
- long[] list = new long[10000];
- System.out.print("Array: ");
- /*Method*/
- long startTime = System.currentTimeMillis();
- ThreadCollatz T1 = new ThreadCollatz(a,b,list);
- T1.start();
- /*Collatz T2 = new Collatz(a,b,list);
- T2.start();*/
- //collatzmethod.findSequence(a,b,list);
- long endTime = System.currentTimeMillis();
- /*Output*/
- System.out.println("That took " + (endTime - startTime) + " milliseconds");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement