找出程序错误并按程序原意修改为可正常运行的程序。
错误程序:
/**
* 找程序错误 错误描述:
* 错误1: …… 在JBuilder的项目HTML文档中;
* 错误原因: …… 或通过javadoc产生的HTML文档中;
* 更正: ……
* 错误n: ……
* 错误原因: ……
* 更正: ……
* 找出程序错误,并根据程序意图在JBuilder中更正程序,通过编译并可运行。
* 该程序为多次计算两个数之和,两个数通过键盘输入,加法通过继承接口的类完成。
* 该程序源代码文件名为Test_Add.java
*/public class Test_Add {
static int ARRAY_MAX_VALUE = 10;
static int ADD_XY_COUNT = 10000;
int x,y,z;
public static void main(String[] args) {
for(int i=0;i<ADD_XY_COUNT;i++){
byte[] number1 = new byte[ARRAY_MAX_VALUE];
byte[] number2 = new byte[ARRAY_MAX_VALUE];
char[] c = new char[ARRAY_MAX_VALUE];
/* 读第一个数 */
System.in.read(number1);
c = (char)number1;
System.out.println("number1 = " + c);
x = number1;
System.out.println("x = " + x);
/* 读第二个数 */
System.in.read(number2);
c = (char)number2;
System.out.println("number2 = " + c);
y = number2;
System.out.println("y = " + y);
/* 计算X+Y */
AddXY addxy = new AddXY();
z = addxy.AddXY(x,y);
System.out.println(" x + y = " + z);
}
}
}public class AddXY implements TestInterface {
int z;
AddXY(int x,int y){
z = x + y;
return z;
}
}public interface TestInterface {
int z;
int AddXY(int x,int y){
z = x + y;
return z;
}
}
错误程序:
/**
* 找程序错误 错误描述:
* 错误1: …… 在JBuilder的项目HTML文档中;
* 错误原因: …… 或通过javadoc产生的HTML文档中;
* 更正: ……
* 错误n: ……
* 错误原因: ……
* 更正: ……
* 找出程序错误,并根据程序意图在JBuilder中更正程序,通过编译并可运行。
* 该程序为多次计算两个数之和,两个数通过键盘输入,加法通过继承接口的类完成。
* 该程序源代码文件名为Test_Add.java
*/public class Test_Add {
static int ARRAY_MAX_VALUE = 10;
static int ADD_XY_COUNT = 10000;
int x,y,z;
public static void main(String[] args) {
for(int i=0;i<ADD_XY_COUNT;i++){
byte[] number1 = new byte[ARRAY_MAX_VALUE];
byte[] number2 = new byte[ARRAY_MAX_VALUE];
char[] c = new char[ARRAY_MAX_VALUE];
/* 读第一个数 */
System.in.read(number1);
c = (char)number1;
System.out.println("number1 = " + c);
x = number1;
System.out.println("x = " + x);
/* 读第二个数 */
System.in.read(number2);
c = (char)number2;
System.out.println("number2 = " + c);
y = number2;
System.out.println("y = " + y);
/* 计算X+Y */
AddXY addxy = new AddXY();
z = addxy.AddXY(x,y);
System.out.println(" x + y = " + z);
}
}
}public class AddXY implements TestInterface {
int z;
AddXY(int x,int y){
z = x + y;
return z;
}
}public interface TestInterface {
int z;
int AddXY(int x,int y){
z = x + y;
return z;
}
}
int z;
int AddXY(int x,int y){
z = x + y;
return z;
}
}
接口中只能有抽象方法
还有一个java文件内只能由1个public class
z = x + y;
return z;
}
方法没写返回类型!
{
static int ADD_XY_COUNT = 10000;
public static void main(String[] args)throws IOException
{
int x,y,z;
for(int i=0;i<ADD_XY_COUNT;i++)
{
/* 读第一个数 */
System.out.println("Please input a Number1:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
x = Integer.parseInt(br.readLine());
System.out.println("number1 = " + x);
/* 读第二个数 */
System.out.println("Please input a Number2:");
br = new BufferedReader(new InputStreamReader(System.in));
y = Integer.parseInt(br.readLine());
System.out.println("number2 = " + y);
/* 计算X+Y */
AddXY addxy = new AddXY();
z = addxy.AddXY(x,y);
System.out.println(" x + y = " + z);
}
}
}class AddXY
{
int z;
int AddXY(int x,int y)
{
z = x + y;
return z;
}
}
1.接口里面的方法不能有主体。
2.AddXY类没有实现接口里面的方法
3.还有些类型转换的错误