| Author |
how to display the result with bracket in java?
|
deepika deepi
Ranch Hand
Joined: Jan 23, 2012
Posts: 199
|
|
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
Bartender
Joined: Aug 16, 2005
Posts: 12921
|
|
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.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
you want to surround fruits string by parenthesis?
<edit>Jesper beaten me ;) </edit>
|
 |
deepika deepi
Ranch Hand
Joined: Jan 23, 2012
Posts: 199
|
|
yeah Seetharaman Venkatasamy,
i want to display the output in parenthesis.
the array of strings is taken as input.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4750
|
|
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
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
deepika deepi
Ranch Hand
Joined: Jan 23, 2012
Posts: 199
|
|
yeah,
thank you yaar.. i have used concatenation. i have not come across string.format(). i will try to see that later...
|
 |
 |
|
|
subject: how to display the result with bracket in java?
|
|
|