Java
Write a method countStairs that, given a number of blocks, counts and returns the number of stairs you could build with the blocks. Stairs are built in a staircase with one block for the first step, two for the second step, three for the third step, and so on, like this picture which shows * for each block in a staircase:
* ** ***
If you had 5 blocks, you could only build 2 stairs (which requires 1+2 = 3 blocks) and not 3 stairs (which would require 1+2+3 = 6 blocks). Hint: Use a loop which counts up to calculate the total number of blocks needed for successive steps until you surpass the number of blocks given. You may only use two if statements.
---
countStairs(0)
countStairs(1)
countStairs(2)
countStairs(3)
countStairs(4)
countStairs(5)
countStairs(6)
countStairs(10)
countStairs(15)
---
What I have so far does not work for inputs: 2, 4, 5
public static int countStairs(int blocks) {
int i = 0;
int n = 1;
int count = 0;
while (i < blocks){
i += n;
n++;
}
return n - 1;
}
public static int countStairs(int blocks) {
int n = 1;
while (n <= blocks){
blocks -= n;
n++;
}
return n-1;
}
Java Write a method countStairs that, given a number of blocks, counts and returns the number...
Write a recursive method that counts the number of bowling pins given the number of pins in the back row: 1. public static int numPins (int num) numPins(0)-> 0 numPins(1) → 1 numPins(2)-> 3
Need help with this. Java please!
Write a recursive method that counts the number of bowling pins given the number of pins in the back row: 1. public static int numPins (int num) numPins(0)-> 0 numPins(1) → 1 numPins(2)-> 3
JAVA~ 1. Write a static method named countOdd(my_array) that returns the number of odd integers in a given array. If there are no odd numbers in the array, the method should return 0. If the array is empty, the method should also return 0. For example: Test Result System.out.println(countOdd(new int[]{2, 3, 5, 6})); 2 System.out.println(countOdd(new int[]{2})); 0 System.out.println(countOdd(new int[]{})); 0 System.out.println(countOdd(new int[]{-7, 2, 3, 8, 6, 6, 75, 38, 3, 2})); 4 public static int ----------------------------------------------------------------------------------------------------------- 2. Write a static...
P4 us Background) Counts N (Counts minus Background) CountsN (Counts minu 1. 1589 2. 1602 3. 196 6. 19i9 506. 1559.6 15496 443.6 1593 8. 636 9. İ601 10. 1619 1623.6 1558.6 5. 1596 and the Stahdard Deviation (o): Using the data obtained in Step P4, calculate the average count (Nv Σ[M-N.vg)2/(n-I)], i-1, 2, 3, , 10: n-10 σ i-1 Calculate (Ng)" (with the Background subtracted). How close is (N.) 2 to ơ? percentage difference. Which quantity would be a...
Write a program in C++ that, given a seven-digit number, writes to a file every possible seven-letter corresponding to that number. There are 2187 (3 to the seventh power) such words. Include the numbers 0 and 1; just embed them in the words as a 0 and a 1. Example: one possibility for 5701679 would be: LR01OPW. Assume the user correctly enters only 7 digits (no ‘-‘). Read the user input into a char array. Use a recursive function to...
Write a method that counts the occurrences of each digit in a string using the following header: public static int[] count(String s) The method counts how many times a digit appears in the string. The return value is an array of ten elements, each of which holds the count for a digit. For example, after executing int[] counts = count("12203AB3"), counts[0] is 1, counts[1] is 1, counts[2] is 2, and counts[3] is 2. Write a test program that prompts the...
Here is the recursion tree for the above:
I need to know the formula that counts the nodes in that
recursion tree.
An example:
the recursion tree for a selection sort with an array of 4 in the
worst case scenario looks like this:
That is the type of solution I am looking for. Please determine
the formula to count the number of nodes in the recursion tree for
the insertion sort with an array size of 5 (n=5) where...
1) (10 pts) Write a recursive function that counts and returns the number of nodes in a binary tree with the root root, that store an even value. Please use the struct shown and function prototype shown below. (For example, if the tree rooted at root stored 2, 3, 4, 8, 13, 18 and 20, the function should return 5, since there are five even values [2,4,8,18,20] stored in the tree. typedef struct node { int data; struct node* left;...
please write legible, will rate good
1. An insurer is combining two independent blocks of insurance. The number of claims in both blocks are represented by Poisson distributions. Let N(1) and N (2) denote the number of claims in block 1 and block 2, respectively. Define N = N(1) + N(2) Given that P(N(1) = 0) = 0.1108, P(N2) = 1) = 0.31056, P(N = 2) = 0.15394, find EN(2)].