Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Taking Input in String Array

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Taking Input in String Array

    Hi All,

    I am new to JAVA programming. I want to take input as String in Array. Kindly help me how to take input from user in String Array.

    For e.g: Hello World then Hello should be stored in index [0] and World in index [1].

    Kindly help.

    Thanks and Regards,
    Hasan


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Taking Input in String Array

    This is the first result when googling "java arrays": Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

    What part of this are you stuck on? What have you tried? What worked, what didn't work? How didn't it work? Be specific, post an SSCCE, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Taking Input in String Array

    Actually i want to reverse the order of the string. For example if someone give input as "hello world" it should reverse it to "world hello".
    Remember. I don't want to use any function.

    Can anybody help me out.

    Thanks and Regards,
    Hasan

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Taking Input in String Array

    Quote Originally Posted by syehjafa View Post
    Actually i want to reverse the order of the string. For example if someone give input as "hello world" it should reverse it to "world hello".
    Remember. I don't want to use any function.

    Can anybody help me out.

    Thanks and Regards,
    Hasan
    Smells like a homework assignment. How would you do this by hand, with a piece of paper and a pencil? Write that out, and you'll have an algorithm that should be pretty easy to translate to code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Taking Input in String Array

    I don't want to use any function
    You will have to use some methods. Which ones are you allowed to use?
    There is no way to get at the contents of a String without using a method.

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Taking Input in String Array

    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #7
    Member
    Join Date
    Jun 2011
    Posts
    94
    My Mood
    Amazed
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: Taking Input in String Array

    I am new to Java too. But I guess this might help you in some way: Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
    Take a look at String Lenght section. I know this is not the thing you look for, but might give you some idea.

  8. #8
    Junior Member madelarbo's Avatar
    Join Date
    Jul 2011
    Location
    Muntinlupa City
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wink Re: Taking Input in String Array

    char[] MadelArray = { 'm', 'a', 'd', 'e', 'l', '.'};
    String MadelString = new String(MadelArray );
    System.out.println(MadelString);

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Taking Input in String Array

    Quote Originally Posted by madelarbo View Post
    char[] MadelArray = { 'm', 'a', 'd', 'e', 'l', '.'};
    String MadelString = new String(MadelArray );
    System.out.println(MadelString);
    ...and?

    Recommended reading: http://www.javaprogrammingforums.com...n-feeding.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Parsing many Ints from a user input String.
    By helpmeplease111 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 7th, 2011, 08:41 PM
  2. taking information from one array into another
    By Stn in forum Object Oriented Programming
    Replies: 1
    Last Post: January 18th, 2011, 11:56 AM
  3. Taking an element out of an array
    By SlckP in forum Collections and Generics
    Replies: 3
    Last Post: May 5th, 2010, 02:26 PM
  4. reading string input then casting it to an int?
    By etidd in forum Java Theory & Questions
    Replies: 2
    Last Post: March 27th, 2010, 11:49 PM
  5. Reading String Input?
    By Morevan in forum Java Theory & Questions
    Replies: 1
    Last Post: January 18th, 2010, 12:16 PM