java中数组中的不兼容类型

java中数组中的不兼容类型,java,arrays,incompatibletypeerror,Java,Arrays,Incompatibletypeerror,我对java非常陌生,对于一项作业,我必须要求输入三个单词,然后以数组的形式逐列垂直打印这些单词。我想我已经走了很长的路,但是由于不兼容的类型问题,我无法打印数字。给出了数组[numb1][0]=word1.charAt(numb1)的错误。java在这里不接受numb1,我如何修复它 import java.util.Scanner; import java.util.Arrays; import java.lang.String; public class assignment51 {

我对java非常陌生,对于一项作业,我必须要求输入三个单词,然后以数组的形式逐列垂直打印这些单词。我想我已经走了很长的路,但是由于不兼容的类型问题,我无法打印数字。给出了
数组[numb1][0]=word1.charAt(numb1)的错误。java在这里不接受numb1,我如何修复它

import java.util.Scanner;
import java.util.Arrays;
import java.lang.String;

public class assignment51
{
   static void main()
  {
      Scanner read=new Scanner(System.in);
      System.out.println("Please enter the first of three words:");
      String word1= read.nextLine();

      System.out.println("Please enter the second of three words:");
      String word2= read.nextLine();

      System.out.println("Please enter the third of three words:");
      String word3= read.nextLine();

      int count1 = word1.length();
      int count2 = word2.length();
      int count3 = word3.length();


      int [] nums = new int [] {count1,count2,count3};
      int max = 0;
      for (int i = 0;i<nums.length;i++)
      {
          if (nums[i] >max)
          {
              max=nums[i];
            }
        }      

        max=max-1;
      String [][] array=new String[max][2];

      for (int numb1 = 0; numb1<(count1-1); numb1++)
      {
          array[numb1][0]= word1.charAt(numb1);
  }

        for (int numb2 = 0; numb2<(count2-1); numb2++)
      {
          array[numb2][1]= (word2.charAt(numb2));
  }

        for (int numb3 = 0; numb3<(count3-1); numb3++)
      {
          array[numb3][2]= (word3.charAt(numb3));
  }


}
}
import java.util.Scanner;
导入java.util.array;
导入java.lang.String;
公共课堂作业51
{
静态void main()
{
扫描仪读取=新扫描仪(System.in);
System.out.println(“请输入三个单词中的第一个:”);
String word1=read.nextLine();
System.out.println(“请输入三个单词中的第二个:”);
String word2=read.nextLine();
System.out.println(“请输入三个单词中的第三个:”);
String word3=read.nextLine();
int count1=word1.length();
int count2=word2.length();
int count3=word3.length();
int[]nums=新的int[]{count1,count2,count3};
int max=0;
对于(int i=0;imax)
{
max=nums[i];
}
}      
max=max-1;
字符串[][]数组=新字符串[max][2];

对于(int numb1=0;numb1您正在尝试将字符分配给字符串。这不起作用。在Java中,字符和字符串是完全不同的动物


您的
数组
应声明为
char[]

返回的
charAt
方法是
char
,但您试图将
char
分配给2D
String
数组的一个元素。您不能将
char
直接分配给
String
;没有这种隐式转换

由于您只分配
char
s,请将
array
的数据类型更改为
char[][]

查看以下内容: