954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to find average

How do you find average from the following code?

On average, how many stars would be displayed by the following algoithm?
On average, how many stars would be displayed if nNum was doubled?

static Random randNumGen = new Random();
public static void main(String[]args)
{
int nNum = 10;
printStar(nNum);
}
public static void printStar(int nNum)
{
if(randNumGen.nextInt(10) < 1)
nNum--;
if(nNum > 0)
{
System.out.print('*');
printStar(nNum);
}
}


And i believe the Big-O notation for this code is O(r^n), or am i wrong?

Thanks

charlesguo25
Newbie Poster
4 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You