aspose file tools*
The moose likes Beginning Java and the fly likes how to display the result with bracket in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to display the result with bracket in java?" Watch "how to display the result with bracket in java?" New topic
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

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 8 API documentation
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: 8186
    
  23

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?
Articles by Winston can be found here
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to display the result with bracket in java?