作业帮 > 综合 > 作业

eclipse 输入一段话,看有几个单词 比如输入 what is your name? 输出 what,is,your

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/22 22:33:32
eclipse 输入一段话,看有几个单词 比如输入 what is your name? 输出 what,is,your,name
import java.util.Scanner;
public class CCCC {
public static void main(String[] args) {
String input =null;
Scanner nn = new Scanner(System.in);
System.out.println("输入:");
String a = nn.nextLine().replace(' ',',');
System.out.println(a);
}
}
上面的随手写写,也写对呀……哪有.read()?是next()吗?是nextLine()!这个好用了
再问: 能用 indexof 这个吗 那个方法我们没学过 谢谢了~~
再答: 方法是不断学习的,你只用你学过的,以后不学了?? public int indexOf(int ch, int fromIndex)返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。 这个你看合适不??肯定不合适呀!
再问: 问题是老师让用那个啊 。。。。我用这个不给分。。。。帮帮忙啦