前提・実現したいこと
現在、九桁のString
型の数字を九回入力しそれを一文ずつ配列に収納して、表示しようとしています。ですが、収納しようとするときにエラーが出てしまい配列に追加できません。
直し方を教えてください。
発生している問題・エラーメッセージ
test02.java:19: エラー: 不適合な型: charをStringに変換できません: answers[i] = boards[ti].charAt(i); ^ エラー1個
該当のソースコード
java
1import java.util.Scanner; 2public class test02 3{ 4 static int loop=0; 5 static String answers[] ={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"}; 6 static String boards[] ={"0","0","0","0","0","0","0","0","0"}; 7 public static void main(String[] args) 8 { 9 Scanner sc = new Scanner(System.in); 10 System.out.println("九桁の数字を入力してください。"); 11 for(int i=0;i<9;i++){ 12 int dan=i+1; 13 System.out.print(">"+dan+">"); 14 boards[i] = sc.next(); 15 } 16 int end=0; 17 for(int ti=0;end==1;ti++){ 18 for(int i=0;i<9;i++){ 19 answers[i] = boards[ti].charAt(i); 20 } 21 } 22 23 for(String answer:answers){ 24 System.out.print(answer+" "); 25 loop++; 26 if(loop==9){ 27 System.out.println(); 28 loop=0; 29 } 30 } 31 } 32}
補足情報(FW/ツールのバージョンなど)
java jdk-14.0.2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。