Results 1 to 8 of 8
  1. #1
    pr3diker is offline Member
    Join Date
    Dec 2010
    Location
    Netherlands
    Posts
    6
    Rep Power
    0

    Exclamation String Replacement

    Hi, I'm going to start to learn Java outside of college. Learning Java in making own programs etc. Not scholar programs.
    But I have a problem in getting text back. What do I need to add to this text?

    package ontsleuteling1;

    public class Replace
    {
    public static String replacement(String args[])
    {
    String str="ryhhf,MleiDffkwstkGyyoFfwTloIyykFbols2.Pyykfm RsuLwGlzosksiFihlisdlyOfkSsiKswsiligGsfbsip.RsoItm mskLz978.245.823.456Gkfso,Gfivf";


    str.replaceAll( "F","O" );
    str.replaceAll( "f","o" );

    str.replaceAll( "G","G" );
    str.replaceAll( "g","g" );

    str.replaceAll( "H","L" );
    str.replaceAll( "h","l" );

    str.replaceAll( "I","N" );
    str.replaceAll( "i","n" );

    str.replaceAll( "R","H" );
    str.replaceAll( "r","h" );

    str.replaceAll( "V","Z" );
    str.replaceAll( "v","z" );

    str.replaceAll( "Y","A" );
    str.replaceAll( "y","a" );

    return str;
    // System.out.print(str); --> doesn't work, why not?


    }

    }

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    replaceAll method returns another string. So your code should look like

    str=str.replaceAll( "F","O" );
    Swastik

  3. #3
    pr3diker is offline Member
    Join Date
    Dec 2010
    Location
    Netherlands
    Posts
    6
    Rep Power
    0

    Default

    okay, thanks. I replaced. Could you tell me why I can't put the System.out.println("str"); there?
    Last edited by pr3diker; 12-16-2010 at 11:53 AM. Reason: incorrect english

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    You have a return statement before that, so the flow control will never reach to that line. You may put that print statement before return.
    Swastik

  5. #5
    pr3diker is offline Member
    Join Date
    Dec 2010
    Location
    Netherlands
    Posts
    6
    Rep Power
    0

    Default

    Console : Exception in thread "main" java.lang.NoSuchMethodError: main

  6. #6
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Have you coded the main function in your class?
    Swastik

  7. #7
    pr3diker is offline Member
    Join Date
    Dec 2010
    Location
    Netherlands
    Posts
    6
    Rep Power
    0

    Default

    it works now :)

    package ontsleuteling1;

    public class Replace
    {
    public static void main(String args[])
    {

    String str="ryhhf,MleiDffkwstkGyyoFfwTloIyykFbols2.Pyykfm RsuLwGlzosksiFihlisdlyOfkSsiKswsiligGsfbsip.RsoItm mskLz978.245.823.456Gkfso,Gfivf";


    str = str.replaceAll( "F","O" );
    str = str.replaceAll( "f","o" );

    str = str.replaceAll( "G","G" );
    str = str.replaceAll( "g","g" );

    str = str.replaceAll( "H","L" );
    str = str.replaceAll( "h","l" );

    str = str.replaceAll( "I","N" );
    str = str.replaceAll( "i","n" );

    str = str.replaceAll( "R","H" );
    str = str.replaceAll( "r","h" );

    str = str.replaceAll( "V","Z" );
    str = str.replaceAll( "v","z" );

    str = str.replaceAll( "Y","A" );
    str = str.replaceAll( "y","a" );

    System.out.println( str + "");


    }

    }

  8. #8
    pr3diker is offline Member
    Join Date
    Dec 2010
    Location
    Netherlands
    Posts
    6
    Rep Power
    0

    Default

    okay, I want to translate that sentence. But it doesn't work proper on this way.

    Do you know how to add this in an array or something? I think that that must help.

    Im not sure.

Similar Threads

  1. Replies: 12
    Last Post: 11-26-2010, 08:33 AM
  2. Replies: 1
    Last Post: 11-04-2010, 06:53 PM
  3. shared sub visual basic/ java replacement?
    By dinosoep in forum New To Java
    Replies: 3
    Last Post: 08-11-2010, 02:44 PM
  4. String replacement...
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-19-2010, 04:20 AM
  5. Looking for JGroups replacement
    By asynchrony in forum Networking
    Replies: 4
    Last Post: 10-17-2008, 10:54 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
  •