Question

In: Computer Science

Can you do this please: the code should be java just give me this and I...

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

Solutions

Expert Solution


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*


Related Solutions

How do I calculate the up-market Beta? Can you give me an example please? Can you...
How do I calculate the up-market Beta? Can you give me an example please? Can you give an examp;le of when it is was a good market timer and when it is a bad market timer
Can you fix to me this code plz I just want to print this method as...
Can you fix to me this code plz I just want to print this method as the reverse. the problem is not printing reverse. public void printBackward() {               Node curr = head;        Node prev = null;        Node next = null;               System.out.print("\nthe backward of the linkedlist is: ");               while(curr != null) {            next = curr.next;            curr.next = prev;   ...
Please do in java with code available for copy and with comments so I can follow...
Please do in java with code available for copy and with comments so I can follow along :)\ Develop a program that prints out the sum of each column of a two-dimensional array. The program defines method sumColumn() takes a two-dimensional array of integers and returns a single-dimensional array that stores the sum of columns of the passed array. The program main method prompts the user to enter a 3-by-4 array, prints out the array, and then calls method sumColumns()....
Please give me an example of this java code. Vehicle - number: int - color: String...
Please give me an example of this java code. Vehicle - number: int - color: String - price: double - horsepower: double + Vehicle ( ) + Vehicle (int number) + Vehicle (int number, String color) + Vehicle (int number, String color, double price) + Vehicle (int number, String color, double price, double horsepower) +getnumber( ):int +setnumber(int number):void +getcolor( ):String +setcolor(String color):void +getprice( ):double +setprice(double price):void +gethorsePower( ):double +sethorsePower(double horsePower):void toString( ):String public String toString( ) { return "\n\n number...
Can you please give me a good question that I can present to my class on...
Can you please give me a good question that I can present to my class on Social Obedience? It has to be a question that the class can have a conversation about. Please give answer also.
I applied for an account assistant position in a private firm. Can you give me just...
I applied for an account assistant position in a private firm. Can you give me just some general answers of these questions? a. Which of our values are you uncomfortable with and why? b. Can you give us two examples of the role these values play in your life?
Can you give me an example of the JTB analysis? I really just need an example...
Can you give me an example of the JTB analysis? I really just need an example of it and not the formula. Thank you!
Can you please give me just a general answers of these questions. Observe a 2nd literacy...
Can you please give me just a general answers of these questions. Observe a 2nd literacy lesson taught in the 12 grad classroom. Respond to the following prompt... a. Identify any word recognition strategies used during the lesson. b. Identify vocabulary presented throughout the lesson you believe to be important to the understanding of the lesson.
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import the required classes import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BirthdayReminder {       public static void main(String[] args) throws IOException {        // declare the required variables String sName = null; String names[] = new String[10]; String birthDates[] = new String[10]; int count = 0; boolean flag = false; // to read values from the console BufferedReader dataIn = new BufferedReader(new...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT