|
For a given input value N, find 3^N (Three to the power of N) . You must use a loop! ^_^ (i.e. Don't use Math.pow() if you want full credit in test) getThreeToThePowerOf(0) → 1 getThreeToThePowerOf(1) → 3 getThreeToThePowerOf(3) → 27
Please keep it short Here's the coding bat link (https://codingbat.com/prob/p269627) |
Explanation::
Code is given below
Code ::
public int getThreeToThePowerOf(int N) {
int answer=1;
for(int i=1;i<=N;i++){
answer=answer*3;
}
return answer;
}
Please provide the feedback!!
Thank You!!
For a given input value N, find 3^N (Three to the power of N) . You...
For a given input value N, find 3^N (Three to the power of N) . You must use a loop! ^_^ (i.e. Don't use Math.pow() if you want full credit in test) getThreeToThePowerOf(0) → 1 getThreeToThePowerOf(1) → 3 getThreeToThePowerOf(3) → 27 getThreeToThePowerOf(0) → 1 getThreeToThePowerOf(1) → 3 getThreeToThePowerOf(2) → 9 public int getThreeToThePowerOf(int N) { }
ALSO: d) What is the
power of N(t) in dBm? (use No = 4 10-21W/Hz)
AND: e) What is the formula for the autocorrelation
function RN(τ) ? (leave the answer with No)
4) Let W(t) be AWGN. a) Sketch the PSD of W(t). (Note: This item is not graded in Blackboard. You must hand in your HW to get points for this item.) You can use No to indicate amplitude in your sketch (i.e., no need to replace with the...
When you want a loop to iterate exactly n times, you will typically use one of two standard for loops patterns (see p. 95-96): for (int i = 1; i <= n; i++) for (int i = 0; i < n; i++) Although both of these for loops will output n times, they have different initialization and test conditions. Please give two *examples to describe why it is beneficial to have both patterns. (i.e. think of the initialization condition and...
JAVA Restrictions 1. don't use any other way to implement a loop but recursion (while and for are forbidden). 2. don't use Math.pow\ 3. Pls do not use while or for 1. write a class called MultiplyByItself with a main method 2. the program asks for two integer numbers: x and n. n must be 0 or greater than 0. 3. then the program prints x raised to the n-th power. For example if x is 2 and n is...
Problem Description proving program correctness Consider the following program specification: Input: An integer n > 0 and an array A[0..(n - 1)] of n integers. Output: The smallest index s such that A[s] is the largest value in A[0..(n - 1)]. For example, if n = 9 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 1, since the largest value in...
ALGORITHM RecS(n) // Input: A nonnegative integer n ifn=0 return 0 else return RecS(n+ n n n Determine what this algorithm computes. You must justify your answer. made by this algorithm and solve it. You must justify your answer. same thing using for/while loop(s) developed in (3). You must justify your answer. 1) 2) Set up the initial condition and recurrence relation for the number of multiplications 3) Write the pseudocode for the non-recursive version of this algorithm, i.e., compute...
Use as few 3-input NOR gates as possible to design a bubble detector circuit for 8-bit thermometer code. An n-bit thermometer code represents an integer m, with m 1s followed by (n-m) 0s. 1-bit bubble is an error in coding when a solitary 0 (or 1) is found in between two 1s (or 0s). What is the size of your circuit in terms of the number of NOR gates used? Give a gate level schematic diagram for your circuit. Implement...
CAN SOMEONE HELP WITH THIS? Part 1: power() method We want to write a method that will enable us to calculate a number to a given power. In other words, we are writing a method to mimic what the Math.pow() method we have seen before does. To write this method use the following requirements: The method should return an integer. It should have two parameters x and y both integers. The name of this method will be power(). For the...
2. Assume you have an input array A with entries numbered 1 through n. One intuitive way to randomize A is to generate a set of n random values and then sort the array based on these arbitrary mumbers. (a) (10 pts) Write pseudocode for this PERMUTE-BY-SorTInG method (b) (10 pts) Do best-, average, and worst-case analyses for this method. (c) Extra credit (15 pts): The algorithm RANDOMIZE-In-PLACE(A) A. length for i 1 to n 1 n= 2 swap Ali...
Determine the power series of f(x) = xe^x about the value a = 0. To receive full credit you must explain how you obtained the series and write this series using both summation notation sum cnxn from n=0 to infinity and as an “infinite” polynomial f (x) = c0 + c1 x + c2 x2 + · · · . (a) Use the first SIX terms of the series from part (a) to obtain a decimal approximation for the number...