Locating characters in a string


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Locating characters in a string

  1. #1
    Join Date
    Sep 2002
    Posts
    1

    Locating characters in a string

    Is it possible to pick characters out of a string and add them as values?

    such as:
    input: (by user) 12323

    and output as: 11

  2. #2
    Join Date
    Sep 2002
    Posts
    16
    Try something like this:
    Code:
    String string = new String();
    string = "12345";
    int counter;
    int value;
    value = 0;
    for (counter=0;counter<string.length();counter++)
      {
      value += Integer.parseInt(string.substring(counter,counter+1));
      }
    System.out.print(value);
    Jayceepoo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center