使用Character.getNumericValue()时出错(Error when using Character.getNumericValue())

编程入门 行业动态 更新时间:2024-10-26 21:33:27
使用Character.getNumericValue()时出错(Error when using Character.getNumericValue())

我的代码是:

for(int i = 0; i < charArray.length; i++) { char charValue = Character.getNumericValue(charArray[i]);

基本上,我试图检索我的char数组中每个项目的数值,但我在编译时收到此错误消息:

incompatible types: possible lossy conversion from int to char

我很困惑,因为我没有处理整数。 我试图寻找解决我的具体问题的方法,但找不到答案。 提前感谢您提供的任何帮助。

My code reads:

for(int i = 0; i < charArray.length; i++) { char charValue = Character.getNumericValue(charArray[i]);

Basically, I am trying to retrieve the numeric value of each item in my char Array, but I am receiving this error message when compiling:

incompatible types: possible lossy conversion from int to char

I am confused because I am not dealing with ints. I tried searching for a resolution to my specific problem but could not find an answer. Thanks ahead of time for any help you provide.

最满意答案

当getNumerValue返回一个整数时,你输入的charValue变量是一个char。

将charValue类型设置为int并再次尝试。

you're typing the charValue variable is a char when getNumerValue returns an integer.

set charValue type to int and try again.

更多推荐

本文发布于:2023-07-19 17:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1184013.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Character   getNumericValue   Error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!