Привет, Я пытаюсь сделать игру в словах, прямо сейчас мне трудно добавить письмо в массив букв. Ошибка в строке 8 ипытается добавить элемент в список
несовместимые типы
найдено: Char
требуется: java.lang.String
import java.util.Scanner;
public class Smartgame {
public static void main(String[] args) {
System.out.println("Complete the puzzle!\nMake sure each row and each column consists of the letters 'S','M','A','R' and 'T' in any order.\nNo letter shall be repeated in any row or any column");
char[][] table = new char[5][5];
charTable(table);
String[] preset = {table[0][0] = 'S', table[0][1] = 'M',table[0][2] = 'A',table[0][3] = 'R',table[0][4] = 'T',table[1][1] = 'T',table[1][2] = 'S',table[1][3] = 'M',table[2][2] = 'R',table[2][4] = 'S',table[3][1] = 'S',table[3][2] = 'M',table[4][2] = 'T',table[4][3] = 'S'};
Scanner input = new Scanner(System.in);
int num = 0;
int[] sums = new int[25];
int sum = 0;
for (int i = 0;i<5;i++){
for (int j = 0; j<5; j++) {
if (table[i][j] == '\0')
num = 0;
else
sum = sum + ((int)table[i][j]);}}
while (sum < 1955){
System.out.println("Please enter a row. (1-5)");
int row = input.nextInt();
if (row > 5)
System.out.println("Invalid entry, please enter a row number from 1-5.");
else
System.out.println("Please a column. (1-5)");
int column = input.nextInt();
if (column > 5)
System.out.println("Invalid entry, please enter a column number from 1-5.");
else
System.out.println("Please enter any of the following letters: 'S','M','A','R' or 'T'");
char letter = input.next().charAt(0);
if (letter == 'S')
preset.push("table["+row+"]["+column+"] = 'S'");
if (letter == 'M')
letter = table[row-1][column-1];
else if (letter == 'A')
letter = table[row-1][column-1];
else if (letter == 'R')
letter = table[row-1][column-1];
else if (letter == 'T')
letter = table[row-1][column-1];
}
}
public static void charTable(char[][] table){
System.out.println(" 1 2 3 4 5 ");
System.out.println(" +---+---+---+---+---+");
for (int i = 0;i<5;i++){
System.out.print(i+1 + " | ");
for (int j = 0; j<5; j++) {
if (table[i][j] == '\0')
System.out.print(" | ");
else
System.out.print("" + table[i][j] + " | ");
}
System.out.println();
System.out.println(" +---+---+---+---+---+");
}
}}
'' S'' является 'char', вы хотите' String', который является '' S "'. – user1803551