Write a C# program that defines and calls a programmer‐defined method that will output a specified number of ‘*’ … for instance if the user calls the method with mystars(10); then the method should output 10 ‘*’ to the screen. This method should be type void and have one parameter. Use your method to output three lines of asterisks of varying amounts: one with 13, one with 42, and one with a number corresponding to your birthday (for instance if you were born on the 5th you’d output 5 asterisks!) CHALLENGE TASK: Write the method such that it returns a string of ‘*’ instead of outputting them. This version would be type string, and you would call it like: Console.WriteLine(mystars(10)); //this would output 10 ‘*’ string strMystring; strMystring = mystars(42); //this would put a string of 42 ‘*’ in the strMystring variable Console.WriteLine(strMystring); //this would actually output the asterisks If you do the challenge program you’ll need to use your challenge function to create the output requested above.
Write a C#
instance if the user calls the method with mystars(10); then the method should output 10 ‘*’ to the screen. This method
should be type void and have one parameter. Use your method to output three lines of asterisks of varying amounts:
one with 13, one with 42, and one with a number corresponding to your birthday (for instance if you were born on the
5th you’d output 5 asterisks!) CHALLENGE TASK: Write the method such that it returns a string of ‘*’ instead of
outputting them. This version would be type string, and you would call it like:
Console.WriteLine(mystars(10)); //this would output 10 ‘*’
string strMystring;
strMystring = mystars(42); //this would put a string of 42 ‘*’ in the strMystring variable
Console.WriteLine(strMystring); //this would actually output the asterisks
If you do the challenge program you’ll need to use your challenge function to create the output requested above.
Step by step
Solved in 2 steps with 2 images