Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class ForestRoad {
- public static void printPath(int n) {
- final int height = 2 * n - 1;
- String[][] forest2D = new String[height][n];
- // Filling the map with trees:
- for (String[] strings : forest2D) {
- Arrays.fill(strings, ".");
- }
- int p = 0;
- for (int i = 0; i < forest2D.length; i++) { // Iterating through each row
- forest2D[i][p] = "*"; // Setting the tree to an asterisk
- if (i < n - 1) { // Filling with asterisks until we reach the right border
- p++;
- } else { // Returning back
- p--;
- }
- }
- for (int i = 0; i < forest2D.length; i++) {
- for (int k = 0; k < forest2D[i].length; k++) {
- System.out.print(forest2D[i][k]);
- }
- if (i == forest2D.length - 1) {
- break;
- } else {
- System.out.println();
- }
- }
- }
- }
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ForestRoad.printPath(scanner.nextInt());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement