import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; public class ServerOperation extends UnicastRemoteObject implements RMIInterface{ protected ServerOperation() throws RemoteException {} public int[] mult(int number) throws RemoteException{ int [] a = new int[5]; String output1=""; for(int i=0; i<=4; i++){ a[i]= (i+1)*number; output1= output1+" "+a[i]; } System.out.println("The multiple: "+ output1 ); //return "The 5 multiples of " +number+" are"+ output1; return a; } // We can also use an array in the implementation of this function public String div(int number) throws RemoteException{ int [] b = new int[number]; String output2=""; for(int i=1; i<=number; i++){ if (number%i==0){ b[i-1]= i; output2= output2+" "+b[i-1]; } } // We can return the array b or the string output2 return "The divisor(s) of " +number+" are"+ output2 ; } public static void main(String[] args){ try { Naming.rebind("//localhost/MyServer", new ServerOperation()); System.out.println("Server ready"); } catch (Exception e) { System.err.println("Server exception: " + e.toString()); e.printStackTrace(); } } }