Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class myThread implements Runnable {
- int limit, tNumber;
- myThread(int x, int y){
- limit = x; tNumber = y;
- }
- public void run() {
- for(int i = 1 ; i <= limit; i++)
- System.out.println(i+"(Thread " +tNumber+ ")");
- }
- }
- class Threading {
- static int getInt(String prompt) {
- System.out.print(prompt);
- while(true){
- try {
- return Integer.parseInt(new Scanner(System.in).next());
- } catch(NumberFormatException ne) {
- System.out.print("That's not a whole number.\n"+prompt);
- }
- }
- }
- public static void main(String[] args) {
- int n = getInt("Enter the number of threads: ");
- int[] priority = new int[n];
- int[] limit = new int[n];
- for(int i = 0; i < n; i++) {
- limit[i] = getInt("Enter the limit of thead "+(i+1)+": ");
- priority[i] = getInt("Enter the priority of thread "+(i+1)+": ");
- while(priority[i] < 1 || priority[i] > 10)
- priority[i] = getInt("The priority should be between 1 and 10: ");
- }
- for(int i = 0; i <n; i++){
- Thread t = new Thread(new myThread(limit[i],i+1));
- t.setPriority(priority[i]);
- t.start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement