Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HollowOctagon {
- public static void drawHorizontal(int leftAlign, char ch, int s) {
- for (int i=0; i<leftAlign; i++) {
- System.out.print(" ");
- } // for
- for (int i=0; i<s; i++) {
- System.out.print(ch);
- } // for
- System.out.println();
- } // drawHorizontal()
- public static void drawVerticals(int leftAlign, char ch, int s) {
- for (int i=0; i<s; i++) {
- for (int j=0; j<leftAlign-s+1; j++) {
- System.out.print(" ");
- } // for
- System.out.print(ch);
- for (int sp=0; sp<3*(s-1)-1; sp++) {
- System.out.print(" ");
- } // for sp
- System.out.println(ch);
- } // for i
- } // drawVerticals()
- public static void drawTopDiagonals(int leftAlign, char ch, int s) {
- for (int i=0; i<s-2; i++) {
- for (int j=0; j<leftAlign-(i+1); j++) {
- System.out.print(" ");
- } // for
- System.out.print(ch);
- for (int sp=0; sp<s+2*i; sp++) {
- System.out.print(" ");
- } // for sp
- System.out.println(ch);
- } // for i
- } // drawTopDiagonals()
- public static void drawLowerDiagonals(int leftAlign, char ch, int s) {
- for (int i=s-3; i>=0; i--) {
- for (int j=0; j<leftAlign-(i+1); j++) {
- System.out.print(" ");
- } // for
- System.out.print(ch);
- for (int sp=0; sp<s+2*i; sp++) {
- System.out.print(" ");
- } // for sp
- System.out.println(ch);
- } // for i
- } // drawLowerDiagonals()
- public static void main(String[] args) {
- char symbol = '*';
- int size = 10;
- int leftAlign = 10;
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter size of octagon (up to 10): ");
- size = scan.nextInt();
- if (size>10) size=10;
- if (size<2) size = 2;
- System.out.println();
- drawHorizontal(leftAlign, symbol, size);
- drawTopDiagonals(leftAlign, symbol, size);
- drawVerticals(leftAlign, symbol, size);
- drawLowerDiagonals(leftAlign, symbol, size);
- drawHorizontal(leftAlign, symbol, size);
- } // main()
- } // class HollowOctagon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement