Created
March 14, 2022 09:13
-
-
Save Fray117/e3837394166d372d5f321efaef3ec422 to your computer and use it in GitHub Desktop.
Generate Horizontal Pyramid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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