Answer:
public class Main
{
public static void main(String[] args) {
System.out.println(starString(4));
}
public static String starString(int n){
double p = Math.pow(2,n);
String s = "";
for(int i=0; i<p; i++)
s += "*";
return s;
}
}
Explanation:
Create a method named starString that takes an integer parameter, n
Get the 2 to the nth power using pow method and set it to the p
Create an empty string that will hold the asterisks
Create a for loop that will iterate p times. Inside the loop, concatenate an asterisk to the s
Return the s
Inside the main method, call the method with an integer parameter
Answer:
The program in Python is as follows:
n = int(input("Integer: "))
product = 1
for i in range(1,n+1):
product*=i
if(i!=n):
print(str(i)+" *",end =" ")
else:
print(i,end =" ")
print(" = ",product)
Explanation:
This prompts the user for integer input
n = int(input("Integer: "))
This initializes the product to 1
product = 1
This iterates through n
for i in range(1,n+1):
This multiplies each digit from 1 to n
product*=i
This generates the output string
<em> if(i!=n):</em>
<em> print(str(i)+" *",end =" ")</em>
<em> else:</em>
<em> print(i,end =" ")</em>
This prints the calculated product (i.e. factorial)
print(" = ",product)
Answer:
The code will get stuck in an infinite loop.
Explanation:
Since val is decreasing by 1 each time it meets the criteria of being smaller than 10, your code will get stuck in an infinite loop since val will always be smaller than 10.
Hope this helps :)
Consider the given data:
Assume packet length=n
Maximum queuing delay= (n–1)D
All packets are of the same length, n packets arrive at the same time to the n input ports, and all n packets want to be forwarded to different output ports.
a) The maximum delay for a packet for the memory = (n-1)D
b) The maximum delay for a packet for the bus = (n-1)D
c) The maximum delay for a packet for the crossbar switching fabrics= 0