| | |
multithreaded java bubble sort
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2007
Posts: 4
Reputation:
Solved Threads: 0
hey i am doing an assignment and it is to create a multithreaded bubble sort but i am having problems initialising and assigning jobs to the threads. i have included the classes and the errors i am getting and was wondering if someone could tell me what is going wrong. CHEERS
ERRORS
C:\Documents and Settings\rich\Desktop\OOA\Thread Assignment>javac Sort1.java
Sort1.java:37: cannot find symbol
symbol : variable t1
location: class Sort1
if (Thread.currentThread() == t1) {
^
Sort1.java:50: cannot find symbol
symbol : variable t2
location: class Sort1
else if (Thread.currentThread() == t2) {
^
Sort1.java:64: cannot find symbol
symbol : variable t3
location: class Sort1
else if (Thread.currentThread() == t3) {
^
Sort1.java:79: cannot find symbol
symbol : variable t4
location: class Sort1
else if (Thread.currentThread() == t4) {
^
4 errors
ERRORS
C:\Documents and Settings\rich\Desktop\OOA\Thread Assignment>javac Sort1.java
Sort1.java:37: cannot find symbol
symbol : variable t1
location: class Sort1
if (Thread.currentThread() == t1) {
^
Sort1.java:50: cannot find symbol
symbol : variable t2
location: class Sort1
else if (Thread.currentThread() == t2) {
^
Sort1.java:64: cannot find symbol
symbol : variable t3
location: class Sort1
else if (Thread.currentThread() == t3) {
^
Sort1.java:79: cannot find symbol
symbol : variable t4
location: class Sort1
else if (Thread.currentThread() == t4) {
^
4 errors
Java Syntax (Toggle Plain Text)
// Sort1.java import java.util.Scanner; //import the class which allows you to scan for input public class Sort1 implements Runnable { public int x; public void run() { int hold; Scanner kb = new Scanner (System.in); int num1, num2, num3, num4, num5; //data entry //Read the numbers as they are entered System.out.print("Enter the first number:"); System.out.flush(); // flush the buffer of all current input num1 = kb.nextInt(); // use the scanner to get input and call it num1 System.out.print("Enter the second number:"); System.out.flush(); num2 = kb.nextInt();// use the scanner to get input and call it num2 System.out.print("Enter the third number:"); System.out.flush(); num3 = kb.nextInt();// use the scanner to get input and call it num3 System.out.print("Enter the fourth number:"); System.out.flush(); num4 = kb.nextInt();// use the scanner to get input and call it num4 System.out.print("Enter the fifth number:"); System.out.flush(); num5 = kb.nextInt();// use the scanner to get input and call it num5 if (Thread.currentThread() == t1) { while (num1 < num2) { /* compare the two neighbors num1 and num2 */ hold = num1; num1 = num2; num2 = hold; System.out.print(Thread.currentThread().getName() + " value is " + x); } } else if (Thread.currentThread() == t2) { while (num2 < num3) { /* compare the two neighbors num2 and num3 */ hold = num2; num2 = num3; num3 = hold; System.out.print(Thread.currentThread().getName() + " value is " + x); } } else if (Thread.currentThread() == t3) { while (num3 < num4) { /* compare the two neighbors num3 and num4 */ hold = num3; num3 = num4; num4 = hold; System.out.print(Thread.currentThread().getName() + " value is " + x); } } else if (Thread.currentThread() == t4) { while (num4 < num5) { /* compare the two neighbors num4 and num5 */ hold = num4; num4 = num5; num5 = hold; System.out.print(Thread.currentThread().getName() + " value is " + x); } } else { System.out.print("The sort has finished:" + num1 + num2 + num3 + num4 + num5); } } }
Java Syntax (Toggle Plain Text)
// TestSort1.java public class TestSort1 { public static void main( String []argv ) { Sort1 s = new Sort1(); Thread t1 = new Thread(s); Thread t2 = new Thread(s); Thread t3 = new Thread(s); Thread t4 = new Thread(s); Thread t5 = new Thread(s); t1.start(); t2.start(); t3.start(); t4.start(); t5.start(); } }
You've created the variables in TestSort1 and try to use them in Sort1. Doesn't work that way.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Other Threads in the Java Forum
- Previous Thread: problem in opening a file with application using java
- Next Thread: Desperate help
Views: 1606 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addball addressbook android api append apple applet application arguments array arrays automation binary bluetooth button chat class classes client code component css csv database draw eclipse ee error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaarraylist javaprojects jmf jni jpanel julia jvm key linux list loan loop map method methods mobile netbeans newbie number object oracle output packets phone print problem program programming project recursion reporting robot scanner screen se server service set size sms socket software sort sql stream string swing test threads time transfer tree ubuntu windows wrong






