Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // drawing ascii triangles,
- // this program took some trouble to code
- // and had to install new Java compiler... :/
- import java.util.Scanner;
- class Pyramid {
- // #wtf Java is such a bother...
- // int width;
- // int segments;
- static void repeat(char ch, int n) {
- while(n-- > 0) System.out.print(ch);
- return;
- }
- static void drawRow(int width, int x) {
- repeat(' ', x);
- repeat('#', width-2*x);
- System.out.println();
- return;
- }
- static void drawUpper(int width) {
- int x, max = (width/2);
- for(x = 0; x <= max; x++) drawRow(width, x);
- return;
- }
- static void drawLower(int width) {
- int x, max = (width/2);
- for(x = 0; x <= max; x++) drawRow(width, max-x);
- return;
- }
- public static void main(String[] args) {
- int i, width, segments;
- Scanner sc = new Scanner(System.in);
- System.out.print("[width, segments] please: ");
- width = sc.nextInt();
- segments = sc.nextInt();
- sc.close();
- for(i = 0; i < segments; i++) {
- if((i % 2) == 0) drawUpper(width);
- else drawLower(width);
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement