NumberFactor
View Answers
September 28, 2008 at 5:29 PM
hi Dione
use this code, if u want more test use do while loop for continues
like do{
}while(cond)
this is the code
public class Factor {
public void show(int num){
for (int i =1 ; i<= num; i++){
if(num%i == 0){
System.out.println(i);
}
}
}
public static void main(String s[]){
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
System.out.println("Enter a Number");
int n =0;
try{
n = Integer.parseInt(br.readLine());
}catch(IOException ie){
System.out.println("IOException Error");
}
new Factor().show(n);
}
}
Rajanikant
September 29, 2008 at 3:52 PM
Hi,
import java.io.*;
public class FactorialDemo{
public static void main(String[] args) {
try{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the number!");
int a= Integer.parseInt(buff.readLine());
int fact = 1;
System.out.println("Factorial of " +a+ ":");
for (int i= 1; i<=a; i++){
fact=fact*i;
}
System.out.println(fact);
}
catch (Exception e){
System.out.println("found error: " + e);
}
}
}
-----------------------------------
Read for more information.
http://www.roseindia.net/java/beginners/Factorial.shtmlThanks.
Amardeep
Related Tutorials/Questions & Answers: