Looping Through ASCII Art in Java: Solving a Homework Predicament

  • Context: Comp Sci 
  • Thread starter Thread starter Hiche
  • Start date Start date
  • Tags Tags
    Java Loop
Click For Summary

Discussion Overview

The discussion revolves around a homework assignment requiring participants to print ASCII art using loops in Java. The specific challenge involves creating a pattern of asterisks that increases in a particular sequence, with some participants expressing confusion about the requirements and the logic needed to implement the solution.

Discussion Character

  • Homework-related
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant describes the homework task of printing a specific ASCII art pattern, noting the increasing sequence of stars as 2, 4, 2, 4, etc., and proposes a mathematical series to represent this pattern.
  • Another participant questions the proposed sequence of asterisks, suggesting that a consistent increase by 2 stars per line would create a more aesthetically pleasing pattern.
  • A third participant mentions the challenge of integrating this task into a larger program that prints their country's flag, indicating a broader context for the homework assignment.
  • A later reply provides a sample loop structure, outlining a method to count stars while incorporating a conditional statement to skip certain counts, although it does not clarify how this relates to the original pattern discussed.

Areas of Agreement / Disagreement

Participants express differing views on the correct pattern of star increments, with some supporting the original assignment's sequence while others advocate for a simpler, consistent increase. The discussion remains unresolved regarding the optimal approach to the ASCII art task.

Contextual Notes

There are limitations in the clarity of the assignment's requirements, particularly regarding the expected pattern of asterisks. Participants also express varying levels of understanding about loops and conditionals, which may affect their ability to implement the solution.

Hiche
Messages
82
Reaction score
0
..so, we have been assigned a homework to print a certain ASCII art using only loops and methods. We can also use the built-in math methods such as the exponential one and whatnot.

Basically, we have been asked to print an increasing loop that goes as follows:
Code:
           *
          ***
        *******
       *********
     *************
..and so on, so forth. Notice how the stars increase by 2 then by 4, then by 2 then by 4. The sequence in which the stars are increasing within is 2,4,2,4,2,4,2,4...I managed to find the series for that: 3 + (-1)^n or 2 + 2 * (n % 2) where n >= 1.

Is there a way to use that in a loop? I'm slightly bewildered at the moment as this problem overwhelms my basic understanding on loops.
 
Physics news on Phys.org
Hiche said:
..so, we have been assigned a homework to print a certain ASCII art using only loops and methods. We can also use the built-in math methods such as the exponential one and whatnot.

Basically, we have been asked to print an increasing loop that goes as follows:
Code:
           *
          ***
        *******
       *********
     *************
..and so on, so forth. Notice how the stars increase by 2 then by 4, then by 2 then by 4. The sequence in which the stars are increasing within is 2,4,2,4,2,4,2,4...I managed to find the series for that: 3 + (-1)^n or 2 + 2 * (n % 2) where n >= 1.

Is there a way to use that in a loop? I'm slightly bewildered at the moment as this problem overwhelms my basic understanding on loops.
Are you sure about how the numbers of asterisks in a line increase? It would make more sense to me and would make a nicer pattern if they increased by 2 each line.
 
Unfortunately, this is how our instructor assigned us to do. I tried like everything, but no avail. This is just a fraction of a larger program that prints my country's flag.

Is there a way to do that?
 
The counting loop would look something like this.

Code:
for (int i = 0; i < ROW_LIMIT; i++}
{
   starCount = 2*i + 1;
   // The if block skips 5, 11, 17, 23, etc.
   if (starCount % 3 == 2) 
   {
      continue; 
   }
   // Code to calculate the number of spaces to print, and print starCount asterisks
}
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K