Answer:
The power function can be written as a recursive function (using Java) as follows:
- static int power(int x, int n)
- {
- if(n == 0){
- return 1;
- }
- else {
- return power(x, n-1 ) * x;
- }
- }
Explanation:
A recursive function is a function that call itself during run time.
Based on the question, we know x to the 0th power is 1. Hence, we can just create a condition if n = 0, return 1 (Line 3 - 5).
Next, we implement the logic "x to the nth power can be obtained by multiplying x to the n-1'th power with x " from the question with the code: return power(x, n-1 ) * x in the else block. (Line 6 -8)
In Line 7, power() function will call itself recursively by passing x and n-1 as arguments. Please note the value of n will be reduced by one for every round of recursive call. This recursive call will stop when n = 0.
Just imagine if we call the function as follows:
int result = power(2, 3);
What happen will be as follows:
- run Line 7 -> return power(2, 2) * 2
- run Line 7 -> return power(2, 1) * 2
- run Line 7 -> return power(1, 0) * 2
- run Line 4 -> return 1 (Recursive call stop here)
Next, the return value from the inner most recursive call will be return to the previous call stack:
- power(1, 0) * 2 -> 1 * 2
- power(2, 1) * 2 -> 1 * 2 * 2
- power(2, 2) * 2 -> 1 * 2 * 2 * 2 - > 8 (final output)
Answer:
public class SwitchCase {
public static void main(String[] args) {
int num = 0;
int a = 10, b = 20, c = 20, d = 30, x = 40;
switch (num){
case 102: a += 1;
case 103: a += 1;
case 104: a += 1;
case 105: a += 1;
break;
case 208: b += 1; x = 8;
break;
case 209: c = c * 3;
case 210: c = c * 3;
break;
default: d += 1004;
}
}
}
Explanation:
- Given above is the equivalent code using Switch case in Java
- The switch case test multiple levels of conditions and can easily replace the uses of several if....elseif.....else statements.
- When using a switch, each condition is treated as a separate case followed by a full colon and the the statement to execute if the case is true.
- The default statement handles the final else when all the other coditions are false
A hybrid network is any computer network that uses more than one type of connecting technology or topology. For example, a home network that uses both Wi-Fi and Ethernet cables to connect computers is a hybrid.
Answer:
The best answer is letter D.
Explanation:
Downloading of files without your permission is a form of security threat and attack. You as unwilling victim will have your files and private information stolen.
One of the basics of internet security is to terminate any connection that you have in a network to stop the possible attack or threat. Worst case scenario is we can shut down our computers or devices or gadgets. But if we can just terminate the connection without performing a force shut down on the device, it is much better. This will give us more time to save what we are working on and to prevent losing important works or data. Terminating the connection from the network comes in various activities such as:
*Disconnect from the internet - this is one of the most effective method. As most of the attacks are coming from external threats such a hacking.
*Closing the browser - this could be helpful as well. Hackers are using browser to monitor their victims. And malwares and adwares are most active while we use browsers as they are embedded and using it to propagate to peform their activities.
*Disconnect from the local network - if you have closed the internet connection and any active software that you are working on presently and the downloading of files still persists, probably the attack comes from your local network. You must close any connection that you have within the local network.
*Deleting the recent files you have downloaded - You must delete any recent files that you just downloaded from your email or from the internet. There might be malware embedded in the file. Malwares are used by hackers to get in to their victims computer without them knowing it.
Then after terminating all the connections, you must call on your Instructor's attention. He / She is the authority in charge and must be aware of the situation.
I believe the answer is modem