Write a java program to accept the number from user and do the following :- -Calculate Factorial of a given number. -To check weather given number is prime or not.
import java.io.*; class Factprime extends Thread { int n,i,f; Factprime() { System.out.println(this); start(); } public void run() { try { f=1; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the no: "); n=Integer.parseInt(br.readLine()); for(i=1;i<=n;i++) { f=f*i; } System.out.println("Factorial no:"+f); for(i=2;i { if(n%i==0) break; } if(n==i) { System.out.println("Number is Prime"); } else System.out.println("Number is Not Prime"); } catch(Exception e) {} }} class slip12 { public static void main(String args[]) { Factprime fp=new Factprime(); }}
Write a java program to accept the number from user and do the following :- -Calculate Factorial of a given number. -To check weather given number is prime or not.
Reviewed by
on
April 27, 2015
Rating: