I have this assignment for school that I’ve been staring at for a week and I just can’t understand what to do. I take notes on everything, I complete the corresponding codecademy assignments. Individually, I think I understand, but I can never put anything together to make a functioning program. I am so stressed and frazzled, please tell me it gets a little easier with time.
These are the problems on my assignment. No matter what I do with any of them, I get an error:
- (Decimal to binary) Write a method that parses a decimal number into a binary number as a string.
The method header is:
public static String decimalToBinary(int value)
Write a test program that prompts the user to enter a decimal integer value and displays the corresponding binary value.
Here is a sample run:
Enter an integer: 1451
The binary value is 10110101011
- (Capitalize first letter of each word) Write the following method that returns a new string in which the
first letter in each word is capitalized.
public static void title(String s)
Write a test program that prompts the user to enter a string and invokes this method, and displays
the return value from this method. Here is a sample run:
Enter a string: london england 2015
The new string is: London England 2015
Note that words may be separated by multiple blank spaces
- (Hours, minutes, and seconds) Write a method that returns a string in the form of hour:minute:second
for a given total seconds using the following header:
public static String format(long seconds)
Here is a sample run:
Enter total seconds: 342324
The hours, minutes, and seconds for total seconds 342324 is 23:05:24
Note that a zero is padded to hour, minute, and second if any of these values is a single digit.
- (Pascal triangle) Write a program that displays a Pascal triangle. The program prompts the user to
enter the number of rows and displays the triangle. Here is a sample run:
Enter the number of rows: 8
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
For information on Pascal triangle, see http://www.mathsisfun.com/pascals-triangle.html. You
need to write a method that computes C(m, n) = m!