Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
No se puede mover el signo hash al lado derecho

No puedo mover el signo de almohadilla hacia la derecha para obtener la siguiente forma. Mi código a continuación no funciona como se esperaba, pero necesito obtener la forma a continuación.

por favor como lo hago

 # ## ### #### ##### ###### #######
 public class MyProgramTest { public static void StaircaseChallenge(int n) { for (int i = 1; i <= n; i++) { Console.WriteLine(MySpace(i) + HashSign(i)); } } public static string HashSign(int n) { string t = ""; for (int i = 1; i <= n; i++) { t += "#"; } return t; } public static string MySpace(int n) { string t = "/t"; for (int i = 1; i < n; i++) { t += " "; } return t; } }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Prueba esto:

 public class MyProgramTest { public static void StaircaseChallenge(int n) { for (int i = 1; i <= n; i++) { Console.WriteLine(" ".PadLeft(n - i+1, ' ')+"#".PadLeft(i,'#')); } }

O haga algunos cambios en su código:

 public class MyProgramTest { public static void StaircaseChallenge(int n) { for (int i = 1; i <= n; i++) { Console.WriteLine(MySpace(n - i + 1) + HashSign(i)); } } public static string HashSign(int n) { string t = ""; for (int i = 1; i <= n; i++) { t += "#"; } return t; } public static string MySpace(int n) { string t = string.Empty; for (int i = 1; i < n; i++) { t += " "; } return t; } }
over 4 years ago · Santiago Trujillo Report

0

Cambie solo algunas cosas en su código:

 public class MyProgramTest { public static void StaircaseChallenge(int n) { for (int i = 1; i <= n; i++) { Console.WriteLine(MySpace(i, n) + HashSign(i)); } } public static string HashSign(int n) { string t = ""; for (int i = 1; i <= n; i++) { t += "#"; } return t; } public static string MySpace(int m, int n) { string t = ""; for (int i = 1; i <= n - m; i++) { t += " "; } return t; } }

Tienes que pasar más una variable es n (número de fila) en la función MySpace() para dejar espacio. Cuando pasa el número de fila en la función MySpace(), dejará (número de fila - 1) espacio. Entonces, si ingresa 5, la primera vez dejará 4 espacios y luego pondrá "#" de la misma manera.

over 4 years ago · Santiago Trujillo Report

0

Una forma más eficiente de memoria sería usar la clase StringBuilder.

Para esta situación no es crítico, pero es bueno saberlo.

 // define the amount of steps int n=8; // amount of leading whitespaces, for later usage int padding=0; // this one is the "working" memory, initialized by n + padding whitespaces StringBuilder currentLine=new StringBuilder(new string(' ',n+padding)); // it counts down from the last index to the one indicated by padding for (int i = currentLine.Length-1; i >=padding; i--) { // replace the char at the current index with #; (here: always the index of the last whitespace) currentLine[i]='#'; // display a copy of the current state on the console, Console.WriteLine(currentLine.ToString()); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!