这是我的班级
public class SecretName{
private String str;
private int i;
private int j;
Scanner cycle=new Scanner(System.in);
public SecretName(String str , int i)
{
this.str = str;
this.i = i;
}
public SecretName(String str,int i, int j )
{
this.i = i;
this.j = j;
this.str = str;
}
public void cycleName(String str , int i)// method string and integer
{
System.out.print("Enter string:");
str=cycle.next()+" ";
System.out.print("Enter value:");
i=cycle.nextInt();
int l,len,y;
String str2="";
char x;
len=str.length();
for(l=0;l<len;l++)
{
x=str.charAt(l);
int c=Integer.valueOf(x);
if(i>0)
{
if((c>=97)&&(c<=123-i))
{
c=c+i;
str2=str2+(char)(c);
}
else
{
y=c+i;
c=(y-123)+96;
str2=str2+(char)(c);
}
}
}System.out.println("New string:" +str2);
}
public void cycleName(String str, int i, int j)//method string and 2 integer value
{
String alphabet[][] = {
{ "a", "b", "c", "d", "e" },
{ "f", "g", "h", "i", "j" },
{ "k", "l", "m", "n", "o",},
{ "p", "q", "r", "s", "t",},
{ "u", "v", "w", "x", "y",},
{ "z", "~", "!", "@", "#",}
};
int l=0;
for(i=0; i<6; i++) {//column
for(j=0; j<5; j++)//row
System.out.print(alphabet[i][j] + " ");
System.out.println();
}
System.out.print("Enter string:");
str=cycle.next();
System.out.print("Enter value:");
int n=cycle.nextInt();
int y;
String str2="";
char x;
String len=alphabet[i][j];
for(i=0; i<6; i++) {//column
for(j=0; j<5; j++)//row
{
//x=str.charAt(l);
//int c=Integer.valueOf(x);
if(n>0)
{
if((i>=0)&&(j<=6-n))
{
j=j+n;
str2=str2+(i);
}
else
{
y=i+n;
i=(y-90)+64;
str2=str2+(i);
}
}
}System.out.print("New string: " +str2);
}
}
这是我的扩展课程。
public class MySN extends SecretName
{
public static void main(String[] arg)
{
SecretName cn1 = new SecretName();
cn1.cycleName("abu", 3);
System.out.println(cn1.cycleName());
}
问题是当我运行它时出现此错误:构造函数SecretName.SecretName(String,int,int)不适用 (实际和正式的参数列表长度不同) 构造函数SecretName.SecretName(String,int)不适用 (实际和正式的参数列表长度不同) 有人可以帮帮我吗?
答案 0 :(得分:2)
您需要添加默认构造函数,因为您正在使用main方法。
SecretName cn1 = new SecretName();
将其添加到SecretName
类
public SecretName() {}
答案 1 :(得分:0)
您已经在班级中定义了两个构造函数:
public SecretName(String str , int i) {
//...
}
public SecretName(String str, int i, int j) {
//...
}
它们都需要参数(分别是两个或三个参数)。但是您尝试使用 no 参数调用构造函数:
new SecretName()
您需要添加无参数构造函数:
public SecretName() {
// initialize fields to default values?
// or maybe don't initialize anything?
}
或者您需要为构造函数提供参数:
new SecretName("", 0)
// or...
new SecretName("", 0, 0)
// though you can use any values you like