Note that there are some explanatory texts on larger screens.

plurals
  1. POJava AsciiArt not printing correctly
    primarykey
    data
    text
    <pre><code>import java.util.Scanner; public class asciiart { public static void main(String[] args){ Scanner input = new Scanner(System.in); int number1 = input.nextInt(); int number2 = input.nextInt(); input.close(); if ((number1 &lt; 3) &amp;&amp; (number2 &lt;3)) { System.out.println("Error: both rows and columns less than 3"); System.exit(0); } else if (number2 &lt;3) { System.out.println("Error: columns less than 3"); System.exit(0); } else if (number1 &lt; 3) { System.out.println("Error: rows less than 3"); System.exit(0); } else { asciiArt(number1, number2); } } public static void asciiArt(int columns, int rows) { int dotLength = 0; int xLength = 0; int halfLength = 0; if ((rows &lt; columns) &amp;&amp; (rows % 2 != 0)) { dotLength = (rows - 1) / 2; xLength = columns - (dotLength * 2); halfLength = (rows / 2) + 1; } else if ((columns &lt; rows) &amp;&amp; (columns % 2 != 0)) { dotLength = (columns - 1) / 2; xLength = 1; halfLength = (rows / 2) + 1; } else if ((rows &lt; columns) &amp;&amp; (rows % 2 == 0)) { dotLength = (rows - 2) / 2; xLength = columns - (dotLength * 2); halfLength = (rows / 2) + 1; } else if ((columns &lt; rows) &amp;&amp; (columns % 2 == 0)) { dotLength = (columns - 2) / 2; xLength = 2; halfLength = (rows / 2) + 1; } else if ((columns == rows) &amp;&amp; (columns %2 == 0)) { dotLength = (rows - 2) / 2; xLength = columns - (dotLength * 2); halfLength = (rows / 2); } else if ((columns == rows) &amp;&amp; (rows % 2 != 0)) { dotLength = (rows - 1) / 2; xLength = columns - (dotLength * 2); halfLength = (rows / 2) + 1; } for(int x = 0; x &lt; rows; x++) { for(int z = 0; z &lt; dotLength; z++) { System.out.print("."); } for(int a = 0; a &lt; xLength; a++) { System.out.print("x"); } for(int b = 0; b &lt; dotLength; b++) { System.out.print("."); } if (x &gt; (halfLength - 2)) { dotLength = dotLength + 2; xLength = xLength - 4; } System.out.println(""); dotLength = dotLength - 1; xLength = xLength + 2; } } } </code></pre> <p>The input for a square with even dimensions doesn't turn out right or with different dimensions.</p> <p>Example of issues:</p> <p>6x6 square shows up as:</p> <pre><code>..xx.. .xxxx. xxxxxx .xxxx. ..xx.. ...... </code></pre> <p>4x7 looks like:</p> <pre><code>.xx. xxxx xxxxxx xxxxxxxx xxxxxx xxxx .xx. </code></pre> <p>It works perfectly fine when the columns is bigger than the row (ex: 6x5, 9x6 ...) and odd sided squares.</p> <p>9x7</p> <pre><code>...xxx... ..xxxxx.. .xxxxxxx. xxxxxxxxx .xxxxxxx. ..xxxxx.. ...xxx... </code></pre> <p>5x5</p> <pre><code>..x.. .xxx. xxxxx .xxx. ..x.. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload