• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to display the result with bracket in java?

 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • 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?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
yeah Seetharaman Venkatasamy,

i want to display the output in parenthesis.

the array of strings is taken as input.
 
Winston Gutkowski
Bartender
Pie
Posts: 10257
59
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic