CS XXXXXXXXXXU03 HW
Write two complete java programs to solve the following two problems. Zip up the .java files and submit them.
Make certain to document your code properly.
1) Combination
Combinations in mathematics are the ways of picking several items from a large group, where order does not
matter. For example, there are 6 ways to pick 2 items from a group of 4 items. In mathematics, the number of
combinations of picking k items from a group of n items is denoted as
k
nC , knC , or
k
n
.
)!(!
!
knk
n
Ckn
−
=
Write a method named getNumberOfCombinations(int n, int k) for computing
k
nC using following header:
public static BigInteger getNumberOfCombinations(int n, int k)
Write a test program that prompts the user to enter n and k and displays
k
nC as shown in the following sample run:
Enter n: 4
Enter k: 2
The C(n, k) is 6
Enter n: 500
Enter k: 45
The C(n, k) is 308478774861652780429726759690004642722396007 XXXXXXXXXX
Line Editor
Input a String from the user, then input a command to modify the line and finally output the
esulting string after performing the command.
The commands formats are
Delete: d
-
Append: a
Replace:
old_string>:
The delete command removes all the characters from the start_index to the end_index (both
integers) The first character in the string is start_index is 0. Verify that end_index is greater
than the start_index. If the end_index is longer than the length of the string, use the length of the
string, Examples
Input String=”Rogers State University”
d10-20
Output String→ Rogers Stity
Input String=”Rogers State University”
d5-11
Output String→ Rogete University
Append command just adds the string following the letter a to the end of the cu
ent string
Input String=”Rogers State University”
a’s Hillcats
Output String→ Rogers State University’s Hillcats
Input String=”Rogers State University”
a---Go Cats!
Output String→ Rogers State University---Go Cats!
The replace command matches every occu
ence of the first string and replaces it with the
second string. There may be multiple matches on one string. The string may contain a space so
the separator between the strings is the colon (:) character. It is case sensitive
Input String=”Rogers State University”
rer:XXXX
Output String→ RogXXXXs State UnivXXXXsity
Input String=”Rogers State University”
rER:XXXX
Output String→ Rogers State University
Input String=”Rogers State University”
rUniversity:College
Output String→ Rogers State College