我无法编译该程序,我尝试重写程序并获取错误。如果我删除了新的tes2(kata,key);到新的tes2();错误再次发生,java:21:错误:类tes2中的构造函数tes2不能应用于给定的类型;请帮助!对不起我的英文不好无法编译Java错误变量可能未被初始化
import java.util.*;
import java.io.*;
public class mod2 {
public static void main(String[] args)throws IOException {
String kata;
int key;
System.out.print(" PROGRAM CAESARCHIPER \n");
tes1 obj = new tes1();
tes2 objj = new tes2(kata, key);
obj.inputt();
objj.inputt();
objj.asd();
}
}
class tes1 {
DataInputStream input = new DataInputStream(System.in);
public void inputt() throws IOException{
System.out.print("Input Kata = ");
String kata=input.readLine();
}
}
class tes2 extends tes1{
public String kata;
public int key;
public tes2(String kata, int key){
this.kata=kata;
this.key=key;
}
public void inputt() throws IOException{
System.out.print("Key Encrypt = ");
int key=Integer.parseInt(input.readLine());
}
public void inputt1()throws IOException{
super.inputt();
}
public void asd(){
String hasil = "" ;
for(int i = 0; i < kata.length() ; i++)
{
int ascii = kata.charAt(i);
int cipher = ascii + key ;
hasil = hasil + (char)cipher;
}
System.out.println("Kata Yang Telah Di Encrypt = " + hasil);
}
}
错误消息是非常清楚。你不需要在类tes2中没有参数的构造函数。 – Jens 2014-12-19 07:13:04
在你的课堂上提供构造函数 – 2014-12-19 07:13:40
不错。如果您要求人们阅读,请正确缩进您的代码。 – khelwood 2014-12-19 07:46:44