概述
//Abytecan'tholdavaluehigherthan127//ThisprogramthrowsanArithmeticException//ifaddingtwobytesyieldsavaluethatistoohighpublicclassDebugTwelve2{publicstaticvoidmain(String[...
// A byte can't hold a value higher than 127
// This program throws an ArithmeticException
// if adding two bytes yields a value that is too high
public class DebugTwelve2
{
public static void main(String[] args)
{
byte num1 = 120, num2 = 120, result;
final byte HIGHBYTE = 127;
try
{
allowed = (byte)(HIGHBYTE - num1);
if(num2 > allowed)
throw(new ArithmeticException);
result = (byte)(num1 + num2);
System.out.println("Result is " + result);
}
catch(ArithmeticException error)
{
System.out.println(Byte can't hold value higher than + HIGHBYTE);
}
}
}
---------- compiler ----------
DebugTwelve2.java:14: 错误: 需要'('或'['
throw(new ArithmeticException);
^
DebugTwelve2.java:20: 错误: 需要')'
System.out.println(Byte can't hold value higher than + HIGHBYTE);
^
DebugTwelve2.java:20: 错误: 未结束的字符文字
System.out.println(Byte can't hold value higher than + HIGHBYTE);
^
DebugTwelve2.java:20: 错误: 需要';'
System.out.println(Byte can't hold value higher than + HIGHBYTE);
^
DebugTwelve2.java:20: 错误: 需要';'
System.out.println(Byte can't hold value higher than + HIGHBYTE);
^
DebugTwelve2.java:20: 错误: 不是语句
System.out.println(Byte can't hold value higher than + HIGHBYTE);
^
DebugTwelve2.java:20: 错误: 需要';'
System.out.println(Byte can't hold value higher than + HIGHBYTE);
^
7 个错误
输出完成 (耗时 2 秒) - 正常终止
展开
最后
以上就是大胆柜子为你收集整理的java参数错误_java参数不对怎么弄的全部内容,希望文章能够帮你解决java参数错误_java参数不对怎么弄所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复