我正在制作一个加密程序,用户输入一个单词,然后模式然后将拼字的单词。我不明白这种方法错误
这里是我的错误:
1 error found:
[line: 42]
Error: The method charArray(int) is undefined for the type Cipher
这里是我的代码:
import java.util.Scanner;
public class Cipher
{
public static char cipher (int j){
char[] cipher1 = {'a','b','c','d','e','f','g'};
j = (int) (Math.random() * cipher1.length);//choose a random element from the array
return cipher1[j];
}
public static void main (String[] args){
System.out.print("Please type a sentence to be encrypted\n");
Scanner inputScanner = new Scanner(System.in);
String input = inputScanner.next();
System.out.print("please enter");
input = input.toLowerCase();
int yu = input.length();
char[] charArray = input.toCharArray();
int w=1;
do{
try{
w=2;
System.out.println("please entrer pattern");
String hello = inputScanner.next();
int hello2= Integer.parseInt(hello);
if(hello2<0){
System.out.println("please enter proper number");
w=1;
}
}catch (NumberFormatException f){
System.out.println("please enter proper number");
}
}while (w==1);
System.out.print("your encrypted code is ");
for(int i = 0; i < yu; i++){
System.out.print(charArray(i)); //THIS IS WHERE ERROR IS HIGHLIGHITNG
for(int q = 0; q <= w; q++){
System.out.print(cipher(1));
}
}
}
}
您是否在代码中的任何位置创建了一个名为'charArray'的方法? –
它不是我用它来发送数组 – user3331406