Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test2 {
- public static double[] function(double l, int n) {
- double result[] = new double[10];
- double x = l*n;
- if (n < 0) {
- return null;
- } else if (n > 0) {
- result = new double[n];
- } else {
- return null;
- }
- long f = 1;
- for (int k = 0; k < n; k++) {
- result[k] = Math.pow(l,k) / f * Math.exp(-1);
- if (k > 0) {
- f*=k;
- System.out.println("P(" + k + ") =" + result[k]);
- } else if (k == 0) {
- System.out.println("P(" + k + ") =" + result[k]);
- x *= l;
- } else if (k < 0) {
- throw new IllegalArgumentException("Fehler");
- // System.out.println("P(" + k + ") =" + x);
- }
- }
- return result;
- }
- public static double[] functionNew(double l, int n) {
- double result[];
- if (n > 0)
- result = new double[n];
- else
- return null;
- long f = 1;
- for (int k = 0; k < n; k++) {
- result[k] = Math.pow(l,k) / f * Math.exp(-1);
- if (k > 0) {
- f*=k;
- } System.out.println("P(" + k + ") =" + result[k]);
- }
- return result;
- }
- public static void main(String[] args) {
- function(1.5, 5);
- System.out.println("---------------------------");
- functionNew(1.5, 5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement