WAP输入一个句子并打印该句子中出现“ is”的次数[Java]
只能使用字符串函数
只能使用扫描仪类
没有数组功能或句子拆分
最佳答案
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String input;
input = scan.nextLine();
int index = input.indexOf("is");
int count = 0;
while (index != -1) {
count++;
input = input.substring(index + 1);
index = input.indexOf("is");
}
System.out.println("No of *is* in the input is : " + count);
}
}
关于java - WAP输入一个句子并打印该句子中“is”出现了多少次[Java],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61692378/