OP- azLuffy
OP- azLuffy

Reputation: 51

error: incompatible types: char cannot be converted to char[] charValue = Input.charAt(0);

I am new to Java and I need a program that takes in 4 integer inputs, 4 double inputs, and 3 character inputs. I have the integer and double inputs ready. I really need help getting the character inputs, please help.

I keep getting this error:

incompatible types: char cannot be converted to char[] charValue = Input.charAt(0);

Here's my code:

int[] intValues = new int[4];
double[] floatValues = new double[4]; 
char[] charValue = new char[3];
String Input;


Input = stdin.readLine();
String[] charValues = Input.split("\\s+");
for (int i = 0; i < charValues.length; i++)
    Input = charValues[i];
    charValue = Input.charAt(0);

Upvotes: 1

Views: 12881

Answers (2)

Siddhesh Chalke
Siddhesh Chalke

Reputation: 11

You are getting that error because you are a=trying to assign a single character to character array. It should be like this charValue[index] = Input.charAt(0);

Upvotes: 1

Eran
Eran

Reputation: 393936

You are missing braces in your loop, and you should assign each char to some index of the char array:

for (int i = 0; i < charValues.length; i++) {
    Input = charValues[i];
    charValue[i] = Input.charAt(0);
}

Upvotes: 1

Related Questions