Je suis assez nouveau pour Java et pour une affectation je dois demander trois mots, puis les imprimer verticalement dans un tableau, colonne par colonne. Je pense que je suis allé assez loin, mais je ne peux pas obtenir les numéros imprimés en raison d'un problème de types incompatibles. L'erreur est donnée pour array[numb1][0]= word1.charAt(numb1);
. Le numb1 n'est pas accepté ici par java, comment puis-je résoudre ce problème?Types incompatibles dans les tableaux dans Java
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));
}
}
}
Jetez un oeil à ces: http://stackoverflow.com/questions/7931862/java-int-and-char https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html – Michael