Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
1.5
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static String replace(String t, String[] a, String[] b){ StringBuilder result = new StringBuilder(); StringBuilder word = new StringBuilder(); char c; for(int i=0; i<t.length(); i++){ c = t.charAt(i); if(c == ' ' || c == '.' || i == t.length()-1){ result.append(getReplace(word.toString(), a, b)); result.append(c); word = new StringBuilder(); }else{ word.append(c); } } return result.toString(); } public static String getReplace(String t, String[] a, String[] b){ String result = null, ai; for(int i=0; i<a.length; i++){ ai = a[i]; if(ai.compareToIgnoreCase(t) == 0){ result = b[i]; break; } } if(result == null){ result = t; } return result; } public static void main(String[] args) { String s, t; t = "The Array class provides static methods to dynamically create and access Java arrays. Array permits widening conversions to occur during a get or set operation."; int maxN = 8; String[] a = {"Array", "to", "static", "and", "arrays", "get", "or", "set"}; String[] b = {"aaaaa", "bb", "cccccc", "ddd", "eeeeee", "fff", "gg", "eee"}; println(t); println(a, "a"); println(b, "b"); s = replace(t, a, b); println(s); } public static void println(String[] t, String name){ System.out.println(name + ":"); for(String s : t){ System.out.println(" " + s); } } public static void println(String t){ System.out.println(t); } }
run
|
edit
|
history
|
help
0
Problem_fib
Leetcode 202 Happy Number
classwork
Hi Hypotaneous
Product of Array Except Self
My1
Find Median in Large File of Integers
Merge Sort in Java
Problem 1 : New Wave Sale
test