Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (anonymous):

. v3

OpenStudy (anonymous):

Can you make equations haha?

OpenStudy (anonymous):

Or, how about the quadratic equation, can you make it do that?

OpenStudy (anonymous):

``` import java.util.Scanner; public class PermutationTest{ public static void main(String[] args) { int k, n; Scanner input = new Scanner(System.in); System.out.print("n: "); n = input.nextInt(); System.out.print("k: "); k = input.nextInt(); System.out.println(String.format("%d permute %d = %d", n, k, permute(n,k))); } public static int permute(int n, int k) { int result = 1; for (k = k+1; k <= n; k++) { result *= k; } return result; } } ```

OpenStudy (anonymous):

how would you change this program to do quadratic equation?

OpenStudy (anonymous):

No clue :d

OpenStudy (anonymous):

How would you change it to give you combination, like n choose k?

OpenStudy (anonymous):

"%d permute %d = %d

OpenStudy (anonymous):

Maybe change that?

OpenStudy (anonymous):

my permutation formula is incorrect!

OpenStudy (anonymous):

Yeah, I was confused it wasn't working lol

OpenStudy (anonymous):

So, how would you try to fix it?

OpenStudy (anonymous):

um

OpenStudy (anonymous):

Which lines of code do you not understand?

OpenStudy (anonymous):

ask about one line at a time.

OpenStudy (anonymous):

Well I thought something might be missing here, n = input.nextInt();

OpenStudy (anonymous):

such as?

OpenStudy (anonymous):

The formula for permutations is: \[\Large ^nP_k = \prod_{i=n-k+1}^ni \]

OpenStudy (anonymous):

What ever you want to put for n and k

OpenStudy (anonymous):

Note that \[\Large n! = \prod_{i=1}^ni \]In short, \(n! = ^nP_n\).

OpenStudy (anonymous):

batman, does it not let you enter a number?

OpenStudy (anonymous):

Yeah it does lol

OpenStudy (anonymous):

anyway... you haven't asked any question.

OpenStudy (anonymous):

That's because I'm still experimenting lol, I'm not exactly sure what I'm doing yet.

OpenStudy (anonymous):

Alright, think I'm done with this for tonight, thanks @wio @Kainui @tanya123

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!