• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Need help on writing a pattern.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
]I am supposed to use any type of loops to print out the following pattern:


O

EE

OOO

EEEE

OOOOO

EEEEEE

OOOOO

EEEE

OOO

EE

O

This is what I came up with:



Output:

O
OO
OOO
OOOO
EEEEE
EEEE
EEE
EE
E


Any Help?
 
Sheriff
Posts: 17321
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you understand why that program gave the output that it did?

Think about how to explain the logic in plain English first. Once you can explain it that way, it's a more straightforward process to translate it to Java.

How may O should be printed out in the first line? In the third line?
How many E should be printed out in the second line? In the fourth line?

Do you recognize a pattern in your answers to these questions? What is it?
 
Junilu Lacar
Sheriff
Posts: 17321
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and Welcome to the Ranch!
 
Marshal
Posts: 76861
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch (again)

Thank you for using the code button, but you haven't quite got the tags in the right places. Don't worry; I corrected the tags for you, and doesn't it look better now Unfortunately it shows inconsistent indentation; be very careful to indent your code because it makes it easier for you to find your way around it.
Write System.out.println(); instead of System.out.println("");
Junilu is right; you should seek a pattern and work that out before you write any code.
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic