i want to repeatedly replace e by o from the words Hello World to be Holle Werld

import java.awt.*;
import java.applet.*;
import java.lang.String;
import javax.swing.JOptionPane;

public class StringExercise1
{
     public static void main(String[] args)
          {
               String textString;

             textString = JOptionPane.showInputDialog("Enter a string:");

               replaceAll(textString);

               System.out.println();

               System.exit( 0 );
          }



          public static void replaceAll(String text)
          {
               System.out.println("Here it is with the e and o swapped "
               + text.replaceAll("o","e"));
          }



}

you almost done it...

your function replaceAll should return String... as i can see you send string to function and than in function you replace all chars and than?... nothing...
So if you decide to use function for returning result than remake function like

public static String replaceAll(String text)

now add RETURN in end of function since you'll need to return value to parent class.

and than in line 14 where you call your function should be some changes.
in this line you call replaceAll whick now returns new formed string... So some string (or already defined textString) should receive new formed text.
In example...

...
{...
...
 String result=MyFunction(text);
  System.out.println(result);
...
...
}

 public static String MyFunction(String inputText)
{
   ...
   inputText=InputText + "A";
   return inputText;
}

and you should print result... In your code in line 16 you print blank line...
see example in my line 5.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.