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 7 of 7

Thread: Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

    Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

    If a number has - sign then u should consider it as a negative number.(Input=abc-12t%^&$dcf22 Output=10)


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

    Default Re: Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

    I tried parsing the string and store the number in another string.Once the number start i store it in another string,i keep on appending until I get anything else other than integer.Then I convert the number in string to integer and add it to variable sum. I tried this logic but not able to write correct code. Please send me optimize solution for this problem in Java.

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

    Default Re: Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

    Can you post the code you are having problems with?
    Is this what you are trying to do?
    Input = "2x3x4"
    output = 9
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

    Quote Originally Posted by rjsingh677@gmail.com View Post
    I tried parsing the string and store the number in another string.Once the number start i store it in another string,i keep on appending until I get anything else other than integer.Then I convert the number in string to integer and add it to variable sum. I tried this logic but not able to write correct code. Please send me optimize solution for this problem in Java.
    Your logic sounds correct.
    If you need help with the code you should read the API for String objects in Java.
    String Documentation: String (Java Platform SE 6)

    Especially the methods "length()", "charAt(int i)" and "substring(int from, int to)" could be useful to you.


    If you are still struggling with it after reading the API you might also try to write it in Pseudo-Code and post that; perhaps we can help you translate it into java.

  6. #6
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

    Another way is to use regular expression and find sequence matching in given string and then performing addition operation.

  7. #7
    Member Abhilash's Avatar
    Join Date
    Jun 2014
    Location
    Kolkata, West Bengal, INDIA
    Posts
    108
    My Mood
    Busy
    Thanks
    5
    Thanked 10 Times in 10 Posts

    Default Re: Please help me in writing a Java program to find sum of numbers in a random string.(Input=abc235^%$q!12&3 output=250)

    Welcome Mr manebrahma to the forum. Please read this topic to learn how to post code in code or highlight tags and other useful info for new members. If you have any problem regarding your programs, please post your problems at What's Wrong With My Code? But I guess you already did that part.

    Thank You for your post.

Similar Threads

  1. Beginner Question--Sum of numbers program; Validation
    By javanightmare in forum Loops & Control Statements
    Replies: 2
    Last Post: February 13th, 2014, 09:56 PM
  2. Logic to find adjacency of numbers 0 & 1 in an array
    By kasun.tawlatta in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 3rd, 2013, 09:38 PM
  3. Storing random numbers into a String field
    By ajw1993 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 23rd, 2013, 10:44 AM
  4. File input & output
    By a21j92 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: January 8th, 2013, 04:13 PM
  5. [SOLVED] Java program to generate 10 random integers and then sum computed
    By Lizard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 14th, 2009, 12:33 PM