• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to display the result with bracket in java?

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Good evening,

i am writing an code to display the words with bracket in the result. for example

apple
mango
banana
orange
are the inputs and i want the result like this

(apple)
(mango)
(banana)
(orange)

I take the input in a string


can any one help to get hte expected result?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

deepika deepi wrote:I take the input in a string


A string or an array of strings?

Loop over the array and print each of the elements between brackets. Please try to write some code yourself first, and if you get stuck, post it here and we can help you further.

If you want to know how to make a loop, see The for Statement in Oracle's Java Tutorials.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you want to surround fruits string by parenthesis?

<edit>Jesper beaten me ;) </edit>
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah Seetharaman Venkatasamy,

i want to display the output in parenthesis.

the array of strings is taken as input.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

deepika deepi wrote:i want to display the output in parenthesis.


Well for something as simple as that you could use String concatenation; but personally, I like String.format().
Well worth getting to know.

Winston
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah,

thank you yaar.. i have used concatenation. i have not come across string.format(). i will try to see that later...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic