anonymous
  • anonymous
can someone explain to me what this code does: public class D { static double dp[][]=new double[51][51];static { dp[1][1]=1; for (int i=2;i<=50;i++) for(int j=1;j<=50;j++) dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j; } public static void main(String args[]){ System.out.println("enterhow many lines:s"); Scanner sc= new Scanner(System.in); while (sc.hasNext()) { int n=sc.nextInt(); if(n==0) break; double ans=0; for(int i=1;i<=n;i++) ans+=dp[n][i]; System.out.printf("%d %.0f\n",n,ans); } }}
Computer Science
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions.

anonymous
  • anonymous
can someone explain to me what this code does: public class D { static double dp[][]=new double[51][51];static { dp[1][1]=1; for (int i=2;i<=50;i++) for(int j=1;j<=50;j++) dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j; } public static void main(String args[]){ System.out.println("enterhow many lines:s"); Scanner sc= new Scanner(System.in); while (sc.hasNext()) { int n=sc.nextInt(); if(n==0) break; double ans=0; for(int i=1;i<=n;i++) ans+=dp[n][i]; System.out.printf("%d %.0f\n",n,ans); } }}
Computer Science
chestercat
  • chestercat
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

KonradZuse
  • KonradZuse
alrighty.... Where did you see this? Crazy haha, lets begin.
KonradZuse
  • KonradZuse
static double dp[][]=new double[51][51];static { dp[1][1]=1; for (int i=2;i<=50;i++) for(int j=1;j<=50;j++) dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j; } not too sure why static, but it's basically creating 2 dimensional array starting at 1 not 0 for some reason. Then it's basically storing dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j; so for the first one it goes dp[2][1] = dp[1][0] + dp[0][1] * 1;
KonradZuse
  • KonradZuse
now the main is asking for you to enter a number n. if(n==0) break; double ans=0; for(int i=1;i<=n;i++) ans+=dp[n][i]; System.out.printf("%d %.0f\n",n,ans); } n cannot be 0, it starts at 1, then it runs through and saying ans (which is 0 at first) is = to ans + dp[n][i] which at first would be lets say n = 5, then ans = ans + dp[5][1] + dp[5][2] etc. Then prints it out.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
so if it starts at dp [1][1]. what is stored in the zero? (or does that not matter since we dont actually use it. in addition: if i put in 5. then it does dp[5[ 2] but what is [5][2]/ where did we initialze any values?
KonradZuse
  • KonradZuse
you can start anywhere, which is why n cannot = 0. dp[1][1]=1; is the initialization.
KonradZuse
  • KonradZuse
however it shows a 0 atsome point in that loop, which it's most likely going to be 0, or null.
anonymous
  • anonymous
so when you put in a number, what does it do? what does the dp[][]actually do?
KonradZuse
  • KonradZuse
dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j;
KonradZuse
  • KonradZuse
dp[2][1] = dp[1][0] + dp[0][1] * 1;
KonradZuse
  • KonradZuse
dp[2][1] = 0 dp[1][1] = 1 * 1 = 1. then dp[2][2] = = dp[2][1] + dp[1][2] * 2 =.....
KonradZuse
  • KonradZuse
it seems like it's printing out the line numbers.

Looking for something else?

Not the answer you are looking for? Search for more explanations.