Results 1 to 8 of 8
  1. #1
    radhi16 is offline Member
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default need help with the program

    program for u will be given a string which will have characters and numbers,u have to parse from behind untill u find a character and print rest of the string
    for example hello123world12 = hello123world 12

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,568
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by radhi16 View Post
    program for u will be given a string which will have characters and numbers,u have to parse from behind untill u find a character and print rest of the string
    for example hello123world12 = hello123world 12
    Your example isn't clear to me, care to elaborate?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    radhi16 is offline Member
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    i need a java program for a string which has characters and numbers
    for example
    String s = "hello123world12";
    and i have to use for loop
    and print the string as
    hello123world 12
    i have to read the string from back and stop reading when i find a chracter so in my example when i read d i have to stop reading the string and print hello123world 12.

    i hope i am clear now

  4. #4
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    to do a reverse for loop
    Java Code:
            for(int i = myString.length()-1 ;i>=0; i--){
                System.out.println( myString.charAt(i) );
            }
    to check if its a character or digit, you can use Character class method isLetter
    Java Code:
    if ( Character.isLetter ( .... ) ){
       // record the value of i. this value can be used to do a substring later if you want (using String.substring() method)
    }
    Last edited by JavaHater; 01-08-2011 at 01:50 PM.

  5. #5
    radhi16 is offline Member
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    thank you .if possible can u tell me the full code.it is the assignment given to me.i tried to do it.and 2day by 9:30 i have to submit the code.
    thank you very much

  6. #6
    radhi16 is offline Member
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    the code which u sent me prints the string backwards
    but the code which i want.

  7. #7
    shibbirmcc is offline Member
    Join Date
    Jan 2011
    Location
    Bangladesh
    Posts
    1
    Rep Power
    0

    Default check this

    ////may be this can do

    public static void main(String[] args) {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    while(true)
    try{
    String s = in.readLine().toString();
    String s1="",s2="";

    ////parsing string
    int i=0;
    for(i=s.length()-1;i>=0;i--)
    if( s.charAt(i)>= '0' && s.charAt(i)<= '9')
    continue;
    else break;
    s1 = s.substring(0, i+1);
    s2 = s.substring(i+1);

    System.out.println("Parsed String:::: "+s1+" "+s2);

    }catch(Exception e)
    {
    System.err.println(e);
    }

    }

  8. #8
    radhi16 is offline Member
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

Similar Threads

  1. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  2. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 04:17 PM
  3. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •