Question
Using C# .Fix the code used to to draw shapes shown below to show: public static string drawsquare( int height, int width) - If the
Using C# .Fix the code used to to draw shapes shown below to show:
public static string drawsquare( int height, int width) - If the size is undrawable (if the height or width is less than 1), the method should instead return a string that says "Cannot draw that shape."
public static string drawisocelestriangle( int size) - If the size is undrawable (if it less than 2), the method should instead return a string that says "Cannot draw that shape."
Code:
using System.IO; using System;
public class ShapeDrawer {
public static string DrawSquare(int height, int width) { // Write your code to draw the square here string s =""; for(int i=1;i<=height;i++) { for(int j=1;j<=width;j++) { if(i==1|j==1||i==height||j==width) { s=s+"$"; } else { s=s+" "; } } s = s + " "; } return s; }
public static string DrawIsoscelesTriangle(int size) { // Write your code to draw the triangle here string s =""; for(int i=1;i<=size;i++) { for(int j=1;j<=i;j++) { s=s+"-"; } s = s + " "; } for(int i=size-1;i>=1;i--) { for(int j=1;j<=i;j++) { s=s+"-"; } s = s + " "; } return s; }
}
class Program { static void Main() { Console.WriteLine(ShapeDrawer.DrawSquare(4,5)); Console.WriteLine(ShapeDrawer.DrawIsoscelesTriangle(3)); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started