In: Computer Science
Can you do this please: the code should be java
just give me this and I will finish the rest don't worry about infix or postfix conversion and evaluation.
just I need these two string should give value. and get a new string like this "12+34-/5".
String s = "ab+cd-/e*"
String s1 = "1232451"
I need code giving each character of String s value of strings1 ignoring operators.
example: a = 1, b = 2, c = 32, d = 4, e = 51, then give me new String like "12+324-/51*"
thank you
I hope the following code is what you are looking for.
Substitute.java
------
public class Substitute {
public static String substitute(String s1, String
s2){
String str = "";
int i = 0, j = 0;
char c;
while(i < s1.length()){
c =
s1.charAt(i);
if(Character.isAlphabetic(c)){
str += s2.charAt(j);
j++;
}
else{
str += c;
}
i++;
}
return str;
}
public static void main(String[] args) {
String s1 = "ab+cd-/e*";
String s2 = "1232451";
System.out.println("s1 = " +
s1);
System.out.println("s2 = " +
s2);
System.out.println("After
substitution, it is " + substitute(s1, s2));
}
}
output
---
s1 = ab+cd-/e*
s2 = 1232451
After substitution, it is 12+32-/4*