Discover new knowledge and insights with IDNLearn.com's extensive Q&A database. Discover comprehensive answers from knowledgeable members of our community, covering a wide range of topics to meet all your informational needs.
Sagot :
Final answer:
Explanation of creating a client-server system using RMI for factorial calculation.
Explanation:
Client Side Program
import java.rmi.;
import java.rmi.registry.;
import java.util.Scanner;
public class Client {
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.getRegistry('127.0.0.1', 9000);
FactorialInterface factorial = (FactorialInterface) reg.lookup('Factorial');
Scanner scanner = new Scanner(System.in);
System.out.println('Enter an integer:');
int num = scanner.nextInt();
int result = factorial.calculateFactorial(num);
System.out.println('Factorial of ' + num + ' is ' + result);
} catch (Exception e) {
System.out.println(e);
}
}
}
Server Side Program
public class Server implements FactorialInterface {
public int calculateFactorial(int num) {
int fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
return fact;
}
}
Learn more about Remote Method Invocation (RMI) here:
https://brainly.com/question/13641616
We are happy to have you as part of our community. Keep asking, answering, and sharing your insights. Together, we can create a valuable knowledge resource. Thanks for visiting IDNLearn.com. We’re dedicated to providing clear answers, so visit us again for more helpful information.