早教吧作业答案频道 -->其他-->
为什么定义bytea,且没有超出byte的取值范围,但java还是报错呢?bytescore[]=newbyte[5];score[0]=1;score[1]=2;score[2]=3;score[3]=4;score[4]=5;bytea;a=score[0]+score[1]+score[2]+score[3]+score[4];System.out.println("
题目详情
为什么定义byte a,且没有超出byte的取值范围,但java还是报错呢?
byte score[]=new byte[5];
score[0]=1;
score[1]=2;
score[2]=3;
score[3]=4;
score[4]=5;
byte a;
a=score[0]+score[1]+score[2]+score[3]+score[4];
System.out.println(" 成绩之和为 ="+a);
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from int to byte
at array.main(array.java:16)
byte score[]=new byte[5];
score[0]=1;
score[1]=2;
score[2]=3;
score[3]=4;
score[4]=5;
byte a;
a=score[0]+score[1]+score[2]+score[3]+score[4];
System.out.println(" 成绩之和为 ="+a);
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from int to byte
at array.main(array.java:16)
▼优质解答
答案和解析
进行narrowing conversion(缩小转换)时存在数据丢失的风险,所以编译器会强制你造型.简单说就是你要进行强转,a=(byte)();
看了 为什么定义bytea,且没有...的网友还看了以下:
我算得y'=-(csc(x+y))^2那么y''应该是多少?答案说是2csc^2(x+y)cot( 2020-06-13 …
坐标旋转公式看不懂X'=x*cos(n)+y*sin(n)Y'=-x*sin(n)+y*cos(n 2020-06-14 …
x超过y的一倍以上(列不等式)我有点糊涂、x超过y的一倍以上是什么意思、是X>Y呢、还是X>Y+( 2020-07-15 …
听说训练。数学课上,王刚在看小说,李超在认真听老师讲课。课后,王刚问李超:“我看小说挨批评了。你呢 2020-07-24 …
求教,高数,连续的定义,没有看懂,为什么△y的极限是0,就称在那点连续.连续不就是该点函数值与该点左 2020-11-01 …
年金系数表里面为什么n没有超过50,i没有超过50%,难倒后面就没有了吗, 2020-11-11 …
设y=|x+1+|x-1|,则下列结论中正确的是y没有最小值只有一个x使y取最小值有有有限个x(不止 2020-11-17 …
大家都认为光的速度是最快的,那么有没有比光的速度更快的东西呢?超光速又是怎么回事,人类能不能超光速飞 2021-01-20 …
x^(z\y)是什么意思?x的z\y次方为什么等于x^z的y次方根,这叫什么?我没学过,请高手指点为 2021-01-31 …
y=cos(-2x)的单调增区间是?为什么我没化成y=cos(2X)再做,结果就是[-π/2+kπ, 2021-02-05 …