Почему выдаётся ошибка, когда пишешь на команде больше 7 символов?
import java.util.Arrays;
import java.util.Scanner;
public class Encrypted {
public static void main(String[] args) {
Scanner t = new Scanner(System.in);
Scanner k = new Scanner(System.in);
String text, key;
byte[] result = new byte[1000];
System.out.print("Введите текст для зашифровки: ");
text = t.nextLine();
System.out.print("Введите 4 значный ключ шифрования с пробелами: ");
key = k.nextLine();
//System.out.println();
System.out.println(key);
for (int i = 0; i < text.length(); i++) {
byte[] text_byte = text.getBytes();
byte[] key_byte = key.getBytes();
//if (key_byte[i])
result[i] = (byte) (text_byte[i] + key_byte[i]);
//System.out.print("\n" + (text_byte[i]));
String c_str = new String(result);
System.out.print(c_str);
//System.out.print("\n" + (result[i]));
result[i] = 0;
}
System.out.println();
}
}
Введите текст для зашифровки: 12345678
Введите 4 значный ключ шифрования с пробелами: 1 2 3 4
1 2 3 4
b
R
e
T
h
V
k
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at Encrypted.main(Encrypted.java:29)