void convert(String i, String j){
a1 = int i;
a2 = int j;
}
int sum(int i,int j){
return sum = i + j;
}
public static void main(String[] args){
Test t1 = new Test();
t1.convert(a,b);
t1.sum(a1,a2);
System.out.println(t1.sum(a1,a2));
}
}
可后来dos报错,需要.class
java?新手求救
分享到:
------解决方案--------------------
class Test{
int a1,a2,sum;
String a = 24;
String b = 12;
void convert(String i, String j){
a1 = int i; //字符转转整形不能这样写 ,应该用Integer.parseInt(i)
a2 = int j; //同上
}
int sum(int i,int j){
return sum = i + j;
}
public static void main(String[] args){
Test t1 = new Test();
t1.convert(a,b); //因为a,b是t1的成员,要写成t1.convert(t1.a,t1.b)
t1.sum(a1,a2); //同理 t1.sum(t1.a1,t1.a2)
System.out.println(t1.sum(a1,a2)); //同理t1.sum(t1.a1,t1.a2)
}
}
然后在cmd窗口输入的命令是:
javac Test.java
java Test //新手很容易把这地方写成java Test.class