From 74f4e035a3cdb3000ca49452346c7e166354809d Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Thu, 28 Jan 2016 13:39:35 +0100 Subject: [PATCH] Cosmetics --- Doc/Sd1/statements.xml | 47 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/Doc/Sd1/statements.xml b/Doc/Sd1/statements.xml index fff670f7b..98d57b4e0 100644 --- a/Doc/Sd1/statements.xml +++ b/Doc/Sd1/statements.xml @@ -581,7 +581,7 @@ Decimal value 14 not yet implemented</programlisting> <programlisting language="java">public class XmasTree { - private static void printIndented(int indentation, String s) { + private static void printIndent(int indentation, String s) { if (0 < indentation) { final String format = "%" + indentation + "s%s"; System.out.format(format, "", s); @@ -591,9 +591,9 @@ Decimal value 14 not yet implemented</programlisting> } public static void main(String[] args) { - + // Example: 5 row groups, tree's body loop index ranging from 0 to 4 - + // \ / The tree's top. // -->*<-- // /_\ @@ -609,39 +609,40 @@ Decimal value 14 not yet implemented</programlisting> // /_/_/_/_/_/_/_\ End of tree's body // [___] Bottom trunk line. + + final int numberOfRowGroups = 5; // You may easily change this value. - final int numberOfRowGroups = 5; // You may easily change this - // value. - printIndented(numberOfRowGroups + 1, "\\ /\n"); // Printing the tree's top. - printIndented(numberOfRowGroups - 1, "-->*<--\n"); - printIndented(numberOfRowGroups + 1, "/_\\\n"); - + printIndent(numberOfRowGroups + 1, "\\ /" + "\n"); // The tree's top. + printIndent(numberOfRowGroups - 1, "-->*<--" + "\n"); + printIndent(numberOfRowGroups + 1, "/_\\" + "\n"); + // Part two: The tree's body // for (int rowGroup = 0; // Outer loop printing the - rowGroup < numberOfRowGroups; rowGroup++) { // tree's body. - - printIndented(numberOfRowGroups - rowGroup,"/");// Starting first line of row + rowGroup < numberOfRowGroups; rowGroup++) { // tree's body. + + printIndent(numberOfRowGroups - rowGroup,"/");// Starting first line of row for (int x = 0; x < rowGroup + 2; x++) { // group with (numberOfRows - System.out.print("_\\"); // row) tree body content. } - System.out.println(); // finishing. - + System.out.println(); // Finishing current line. + // Second body line of current group // - printIndented(numberOfRowGroups - rowGroup - 1, ""); // Starting second line of row group with (numberOfRows - row - 1) - for (int x = 0; x < rowGroup + 3;x++) { // tree body content - System.out.print("/_"); - } - System.out.println("\\"); // finishing. + printIndent(numberOfRowGroups - rowGroup - 1, ""); // Starting second line + for (int x = 0; x < rowGroup + 3;x++) { // of row group with + System.out.print("/_"); // (numberOfRows - row - 1) + } // tree body content. + System.out.println("\\"); // Finishing current line. } - + // Part three: The tree's bottom trunk // - printIndented (numberOfRowGroups, "[___]"); // Indenting the bottom trunk ... - } -}</programlisting> + printIndent (numberOfRowGroups, "[___]"); // Indenting the bottom trunk ... + } +} +</programlisting> </answer> </qandaentry> </qandadiv> -- GitLab