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; int lenT = t.length()-1; for(int i=0; i<=lenT; i++){ c = t.charAt(i); if(c == ' ' || c == '.' || i == lenT){ 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 = {"a", "b", "c", "d", "e", "f", "g", "e"}; 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.print(name + ": "); System.out.println(Arrays.toString(t)); } public static void println(String t){ System.out.println(t); } }
run
|
edit
|
history
|
help
0
CSV Parser
4.d
Meena
Value pair analysis
Leetcode 17. Letter Combinations of a Phone Number
// Java Coding Challenge - 07: Print out Fibonacci number 0 - 1000
else weird
cosmology
3
Prime Factors