public static void main(String[] args) { int n = 0; int m = 0; while (true) { try { BufferedReader sisse = new BufferedReader(new InputStreamReader(System.in)); System.out.println("V2ljumiseks vajutage ctrl-C"); System.out.print("Laste arv: "); String s = sisse.readLine(); n = Integer.parseInt(s); if (n < 0) throw new IllegalArgumentException(String.valueOf(n)); System.out.print("6unte arv: "); s = sisse.readLine(); m = Integer.parseInt(s); if (m < 0) throw new IllegalArgumentException(String.valueOf(m)); System.out.println( "Igale lapsele " + String.valueOf(m / n) + " 6una ja " + String.valueOf(m % n) + " j22b yle"); } catch (NumberFormatException e) { System.out.println("Ei ole arv: " + e.toString()); } catch (ArithmeticException e) { System.out.println("Aritmeetikakatkestus: " + e.toString()); } catch (Exception muu) { System.out.println("Probleem: " + muu.toString()); } finally { System.out.println("n = " + n + " m = " + m); } } } // main
/** * Method for calculating the returns on a given rate path, via the definition for the * instantaneous compounded return. u_i = \ln{\frac{S_i}{S_{i-1}}} * * @return the return, as defined. * @exception DemoException thrown if there is a problem with the calculation. */ public ReturnPath getReturnCompounded() throws DemoException { if (pathValue == null || nAcceptedPathValue == 0) { throw new DemoException("The Rate Path has not been defined!"); } double[] returnPathValue = new double[nAcceptedPathValue]; returnPathValue[0] = 0.0; try { for (int i = 1; i < nAcceptedPathValue; i++) { returnPathValue[i] = Math.log(pathValue[i] / pathValue[i - 1]); } } catch (ArithmeticException aex) { throw new DemoException("Error in getReturnLogarithm:" + aex.toString()); } ReturnPath rPath = new ReturnPath(returnPathValue, nAcceptedPathValue, ReturnPath.COMPOUNDED); // // Copy the PathId information to the ReturnPath object. rPath.copyInstanceVariables(this); rPath.estimatePath(); return (rPath); }