Skip to content

Instantly share code, notes, and snippets.

@Fray117
Created March 14, 2022 09:13
Show Gist options
  • Save Fray117/e3837394166d372d5f321efaef3ec422 to your computer and use it in GitHub Desktop.
Save Fray117/e3837394166d372d5f321efaef3ec422 to your computer and use it in GitHub Desktop.
Generate Horizontal Pyramid
import java.util.Scanner;
public class Arrow {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Size: ");
int line = Integer.parseInt(input.nextLine());
int median = line / 2;
int indent = 0;
for (int i = 0; i < line; i++) {
if (i < median && (median * 2 != line)) {
for (int d = 0; d < indent; d++) {
System.out.print(" ");
}
indent++;
} else if (i < median && (median * 2 == line)) {
for (int d = 0; d < indent; d++) {
System.out.print(" ");
}
if (i < median - 1) indent++;
} else {
for (int d = 0; d < indent; d++) {
System.out.print(" ");
}
indent--;
}
System.out.println(">>>>>");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment