Question: Jump to level 1 String stringFields is read from input. stringFields contains fruit names separated by slashes ( ' / ' ) . For each

Jump to level 1
String stringFields is read from input. stringFields contains fruit names separated by slashes ('/'). For each slash in stringFields, increment numOccurrences by 1 and output "Slash found at index " followed by the index of the slash character.
Ex: If the input is grapefruit/orange/apricot/berry/apple/nectarine, then the output is:
Slash found at index 10
Slash found at index 17
Slash found at index 25
Slash found at index 31
Slash found at index 37
Slash occurs 5 times
```
import java.util.Scanner;
public class FindSlashes {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
String stringFields;
int i;
int numOccurrences =0;
stringFields = scnr.next();
/* Your code goes here */
System.out.println("Slash occurs "+ numOccurrences +" times");
}
}
```
Jump to level 1 String stringFields is read from

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!