• Exercise 9
     
    • Class called java.lang.String has a method called replace( oldchar, newchar ), which can be used to replace one character from string to another. But the Java-class does not contain any methods to replace a part of string to another. In this exercice you will create one:
      • Syntax:
        public static String replaceString(String sText, String sSearch, String sReplace);
         
      • For example, if we have text "Today is very rainy day", then command

        sNewText = replaceString( " Today is very rainy day ", "rainy", "sunny" );
         

      • returns text "Today is very sunny day" into variable called sNewText. And command

        sNewText = replaceString("1 <= 5 <= 7", "<=", "is smaller or equal to" );
         

      • returns text "1 is smaller or equal to 5 is smaller or equal to 7"
         
    • Create individual interface for testing this function, where program asks user to give a string to be fixed,
      another to be search for and string that replaces second one.
       
  • Back