Question: write a java code String foodFields is read from input and contains multiple foods all on the same line. Assign convertedFoodFields with a copy of

write a java code String foodFields is read from input and contains multiple foods all on the same line. Assign convertedFoodFields with a copy of foodFields where all occurrences of "scallion" are replaced with "onion".
Ex: If the input is scallion, juice, scallion, then the output is:
onion, juice, onion
this is what;s given
import java.util.Scanner;
public class ReplaceStrings {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
String foodFields;
String convertedFoodFields;
foodFields = scnr.nextLine();
System.out.println(convertedFoodFields);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!