Lorenzo
Lorenzo

Reputation: 197

incompatible types int[] int

I've been searching for a solution to make the integer sum of two string, and create another string. Now I am working with an array, but I get the following error:

I don't know what I'm doing wrong, anybody that can help?

public class Woord {
final String JAVA = "java";

public void woord() {
    System.out.println("Geef een woord in");
    String woord = Input.readString();

    for (int i = 0; i < woord.length(); i++) {
        int b = (int) woord.charAt(i);
        int[] cArray = b;
        int c = (int) JAVA.charAt(i);
        int[] bArray = JAVA.toCharArray();

        System.out.println(cArray);
    }
}

public static void main(String[] args) {
    Woord woord = new Woord();
    woord.woord();
}}

Upvotes: 0

Views: 105

Answers (1)

ekad
ekad

Reputation: 14614

b is an int, but cArray is an int[]. You can't assign an int to an int[]. Try to change this line

int[] cArray = b;

to this

int[] cArray = new int[] { b };

Upvotes: 2

Related Questions