Write a Java program to accept number from user and Calculate factorial of given number and Also check whether given number is prime or not. (Use Thread)
Write a Java program to accept number from user and Calculate factorial of given number and Also check whether given number is prime or not. (Use Thread) Program: import java.io.*; import java.lang.*; class FactPrime extends Thread { String str; int num1, num2, fact=1, flag=1, i; FactPrime(String s, int n) { num1 = n; str = s; setName(str); start(); } public void run() { if(str.equals("First")) { try { for(i=1; i<=num1; i++) { fact = fact*i; sleep(500); } System.out.println("Factorial: "+fact); } catch (InterruptedException e) { System.out.println(e); } } else if(str.equals("Second")) { try { for(i=2;i<num1;i++) { if(num1%i==0){ flag = 0; bre...