What should I edit or do in my code so that I will get the outcome? What could be edited in my code below to acheive the desired outcome? import java.util.Scanner; class program { } class prog1 extends program implements Runnable { private String nVoters = new String(""); public prog1 (String nVote){ nVoters = nVote; } @Override public void run(){ for (int x = 1; x <= input; x++){ System.out.println(" Voter " + x + "\t" + nVoters + "= " ); } } } public class Quiz2 { public static void main(String args[]){ Scanner sc = new Scanner(System.in); for (int x = 0; x < args.length; x++){ System.out.println(args[x]); } System.out.print("Enter number of voters: "); int input = sc.nextInt(); Runnable r = new prog1("Thread #1"); Thread Candidate1 = new Thread(r); Candidate1.start(); r = new prog1("Thread #2"); Thread Candidate2 = new Thread(r); Candidate2.start(); r = new prog1("Thread #3"); Thread Candidate3 = new Thread(r); Candidate3.start(); } }
What should I edit or do in my code so that I will get the outcome?
What could be edited in my code below to acheive the desired outcome?
import java.util.Scanner;
class program {
}
class prog1 extends program implements Runnable {
private String nVoters = new String("");
public prog1 (String nVote){
nVoters = nVote;
}
@Override
public void run(){
for (int x = 1; x <= input; x++){
System.out.println(" Voter " + x + "\t" + nVoters + "= " );
}
}
}
public class Quiz2 {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
for (int x = 0; x < args.length; x++){
System.out.println(args[x]);
}
System.out.print("Enter number of voters: ");
int input = sc.nextInt();
Runnable r = new prog1("Thread #1");
Thread Candidate1 = new Thread(r);
Candidate1.start();
r = new prog1("Thread #2");
Thread Candidate2 = new Thread(r);
Candidate2.start();
r = new prog1("Thread #3");
Thread Candidate3 = new Thread(r);
Candidate3.start();
}
}
Step by step
Solved in 2 steps with 1 images