我無法編譯該程序,我嘗試重寫程序並獲取錯誤。如果我刪除了新的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