Skip to content

Instantly share code, notes, and snippets.

@wanantope
Created October 28, 2024 13:59
Show Gist options
  • Save wanantope/f2611d784e87768d9684b68b9628553e to your computer and use it in GitHub Desktop.
Save wanantope/f2611d784e87768d9684b68b9628553e to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String slovo;
char[][] alfavit = {{'а', 'б', 'в', 'г', 'д', 'е'},
{'ё', 'ж', 'з', 'и', 'й', 'к'},
{'л', 'м', 'н', 'о', 'п', 'р'},
{'с', 'т', 'у', 'ф', 'х', 'ц'},
{'ч', 'ш', 'щ', 'ъ', 'ы', 'ь'},
{'э', 'ю', 'я', ',', '.', '-'}};
Scanner scanner = new Scanner(System.in);
System.out.println("Алфавит: ");
for (int i = 0; i < alfavit.length; i++) {
for (int j = 0; j < alfavit[i].length; j++) {
System.out.print(alfavit[i][j] + " ");
}
System.out.println();
}
System.out.println();
System.out.println("Введите слово для шифрования: ");
slovo = scanner.next(); //абв
System.out.println("Это позиции каждого символа");
for (int i = 0; i < alfavit.length; i++) {
for (int j = 0; j < 6; j++) {
System.out.printf("Буква '%c' находится в строке %d и столбце %d\n", alfavit[i][j], i + 1, j + 1);
}
}
//шифрование
System.out.println("Это сам шифр");
for (int k = 0; k < slovo.length(); k++) {
char letter = slovo.charAt(k);
boolean found = false;
for (int i = 1; i <= 6 && !found; i++) {
for (int j = 1; j <= 6 && !found; j++) {
if (alfavit[i - 1][j - 1] == letter) {
System.out.print((i) + "" + (j) + " "); // Вывод номера строки и столбца
found = true;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment