I am a beginner of Java programming learner. I can't know how to correct the following Java program. Kindly help to let me know how to correct it. Thanks a lot.
public class TMA1Q2 {
public static void main(String[] args) {
System.out.println("Usage: java TMA1Q2 {number of Threads}");
// Create tasks
Runnable taskA = new PrintTwoConcurThreads("Thread A ");
Runnable taskB = new PrintTwoConcurThreads(" Thread B ");
// Create threads
Thread thread1 = new Thread(taskA);
Thread thread2 = new Thread(taskB);
// Start threads
thread1.start();
thread2.start();
}
}
// The task that implements Runnable
class PrintTwoConcurThreads implements Runnable {
private final String TwoConcurThreads;
private String[] args;
public PrintTwoConcurThreads(String numThreads) {
TwoConcurThreads = numThreads;
}
// Override the run() method
@Override
public void run() {
// Print the value input argument times
int numThreads = Integer.parseInt(args[0]);
Thread[] myThread;
myThread = new Thread[numThreads];
for (int i = 0; i < numThreads; i++) {
System.out.println(TwoConcurThreads + i);
}
}
}
Thread[]is useless.