Skip to content

Instantly share code, notes, and snippets.

@imryan
Created October 16, 2013 16:39
Show Gist options
  • Select an option

  • Save imryan/7010889 to your computer and use it in GitHub Desktop.

Select an option

Save imryan/7010889 to your computer and use it in GitHub Desktop.
Replace chars in a string.
import java.util.Scanner;
public class Replace {
public static void main(String[] args) {
// Declare variables
Scanner sc = new Scanner(System.in);
String word = "", newWord = "";
// Get input
word = sc.nextLine();
// Encode string
newWord = word.replace('i', '!');
newWord = newWord.replace('s', '$');
// Output string
System.out.println(newWord);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment