i practicing programming exam , that's 1 of exams. program crashes after first loop , can't figure out why. please help!
int n = int.parse(console.readline()); console.writeline("{0}{1}{0}", new string('-', n / 2), new string('*', n + 2)); (int = 0; < n - 1; i++) { console.writeline("{0}*{1}*{0}", new string('-', n / 2), new string('-', n)); } (int = 0; < n; i++) { console.writeline( "{0}{1}{2}{1){0}", new string('-', ((n - 1) / 2) - i), new string('*', 1 + 2 * i), new string('-', n - 2 * i)); if (i < n / 2) { i++; } else { i--; } }
"{0}{1}{2}{1){0}", your string format error,you need change {1) {1},but seems code never end while input 5! , other input take exception,can explain want ?
"{0}{1}{2}{1}{0}", i changed code method now
static void printdemo(int num) { if (num < 0 || num % 2 == 0) { return;//do nothing } console.writeline("{0}{1}{0}", new string('-', num / 2), new string('*', num + 2)); (int = 0; < num - 1; i++) { console.writeline("{0}*{1}*{0}", new string('-', num / 2), new string('-', num)); } (int = 0; < num; i++) { var t1 = math.abs(num / 2 - i); var t2 = t1 * 2 + 1; var t3 = (num * 2 + 1 - t1 * 2 - t2) / 2; console.writeline( "{0}{1}{2}{1}{0}", new string('-', t1), new string('*', t3), new string('-', t2)); } }
Comments
Post a Comment