使用System.in.read()时键入不匹配

时间:2015-11-18 00:23:39

标签: java types mismatch

我正在尝试用Java编写一个程序来计算一串文本中每个字母的出现次数,并打印出一个直方图,计算出每个字母的数量。我有大部分代码,但在尝试使用System.in.read()时出错。困扰我的代码就是:

 static String sentence = new String();

  public static void main(String[] args) {
    sentence = System.in.read();

当我编译时,我得到:

Error: Type mismatch: cannot convert from int to java.lang.String

当我明确将sentence定义为字符串时,此int的来源是什么?如何解决此错误?

1 个答案:

答案 0 :(得分:1)

是的,$(document).ready(function(){ $('.filter-select').on('change',function(){ var thisVal = $(this).val(); var anotherVal = $('.filter-select').not($(this)).val(); if(thisVal == 'white' && anotherVal == 'blue' || anotherVal == 'white' && thisVal == 'blue'){ window.location.href = 'https://stackoverflow.com/'; } }); }); sentence,但是如果您阅读了String的javadoc,那么您会看到System.inInputStream {1}}返回InputStream.read()(读取的第一个字符的字符代码,如果int命中文件末尾,则返回-1。赋值右侧的类型必须分配给赋值左侧的类型,可以是相同的类或基本类型,子类,如果lhs是接口,则实现接口,或者转换。

如果您想一次阅读多个字符,请查看其他一些read()类。在这种情况下,io也可能有用。

相关问题