java - Number Pyramid like Egyptian with decreasing numbers -
im working on pyramid on java. did stars. want decreasing numbers. i'm using input. assume input 5;
5 545 54345 5432345 543212345
my code is;
int size = 11; (int = 1; <= size; i=i+2) { int spacecount = (size - i)/2; for(int j = 0; j< size; j++) { if(j < spacecount || j >= (size - spacecount)) { system.out.print(" "); } else { system.out.print("*"); } } system.out.println(); }
i'm glad attention. lot.
int size = 11; (int = 1; <= size; i=i+2) { int spacecount = (size - i)/2; for(int j = 0; j< size; j++) { if(j < spacecount || j >= (size - spacecount)) { system.out.print(" "); } else { system.out.print(n); } } system.out.println(); }
something ?
works numbers of 1 - 9.
int h = 2; string spacing = h == 1 ? "" : string.format("%" + (h - 1) + "s", ""); stringbuilder s = new stringbuilder(string.valueof(h)); system.out.printf("%s%s\n", spacing, s); for(int = h; > 1; --i){ system.out.print(spacing.substring(0, - 2)); s.insert(s.length() / 2 + 1, string.valueof(i - 1) + string.valueof(i)); system.out.println(s.tostring()); }
Comments
Post a Comment