This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to print this pattern  RSS feed

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across this small programming question of printing the following pattern


I was trying but i could not achieve it.
I was trying in the following way..



My thought is to if the line number is even, will print the letters in reverse order, but seems it is not working. Could someone please help.
 
author & internet detective
Posts: 39129
723
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The loop in your if statement and your else statement look exactly the same to me. I think you intended to reverse one.
 
kuldeep sidhu
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:The loop in your if statement and your else statement look exactly the same to me. I think you intended to reverse one.


I am using this in if condition



This is working as expected. I just get this working by debugging again and again. But to me, this seems bit complicated. Do you have any other simple way of doing the same.

And also i am bit confused about putting *. If i am adding it before printing the letter,it will add at the start of each line. And same with printing after the letter, it will append at the end of each line. How to achieve the desired output.
 
Bartender
Posts: 10750
68
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

kuldeep sidhu wrote:This is working as expected. I just get this working by debugging again and again. But to me, this seems bit complicated. Do you have any other simple way of doing the same.


Yes, and you almost had it before you started changing things. Read Jeanne's response again. Carefully.

Winston
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!