Thanks a lot. That worked like a charm.
I have edited the code in following way.
FacImpl
import java.rmi.server.*;
import java.util.*;
import http:
import java.math.*;
public class FacImpl extends UnicastRemoteObject implements FacInt
{
int limit;
public FacImpl(int limit) throws Exception
{
super();
this.limit = limit;
}
public int fac(int x) throws Exception
{
if (x > limit)
throw new IllegalArgumentException(
String.format("Cannot calulate Fac beyond %1", limit));
else{
int i,j=1;
for(i=x;i>1;i--)
j=j*i;
return j;
}
}
}
FacServer
import java.rmi.*;
import java.util.*;
import java.io.*;
import java.math.*;
public class FacServer
{
public static void main(String a[]) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a number: ");
String s = null;
try {
s = br.readLine();
} catch(IOException ioe) {
System.err.println(ioe.getMessage());
}
int limit = Integer.parseInt(s);
if ((a != null) && (a.length > 0)) {
try {
int temp = Integer.parseInt(a[0]);
if (temp > 0)
limit = temp;
} catch (NumberFormatException e) {
}
}
FacImpl obj = new FacImpl(limit);
Naming.rebind("FAC",obj);
System.out.println("Server started");
}
}
Also I wanted to show the factorial result in server instead of client. Is it possible to do so?