简体   繁体   English

错误:类型不兼容:char 无法转换为 char[] charValue = Input.charAt(0);

[英]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.我是 Java 新手,我需要一个接受 4 个整数输入、4 个双精度输入和 3 个字符输入的程序。 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);不兼容的类型:char 不能转换为 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);

You are missing braces in your loop, and you should assign each char to some index of the char array:您的循环中缺少大括号,您应该将每个char分配给字符数组的某个索引:

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

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);应该是这样的 charValue[index] = Input.charAt(0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:类型不兼容:对象无法转换为char - Error: incompatible types: Object cannot be converted to char 错误:类型不兼容:char无法转换为String - error: incompatible types: char cannot be converted to String 错误:不兼容的类型:char[] 无法转换为 char (java) - Error: incompatible types: char[] cannot be converted to char (java) charAt错误“char无法转换为字符串” - charAt error “char cannot be converted to string” 有关不兼容类型的错误:字符串无法转换为char - error about incompatible types: String cannot be converted to char 不兼容的类型:char[] 无法转换为 CharSequence - incompatible types: char[] cannot be converted to CharSequence 错误:类型不兼容:字符串无法转换为char opp = JOptionPane.showInputDialog(“ Enter Method”); - error: incompatible types: String cannot be converted to char opp = JOptionPane.showInputDialog(“Enter Method”); 不兼容的类型:尝试从文本输入中获取文本时,无法将 Editable 转换为 char[] - incompatible types: Editable cannot be converted to char[] when trying to get the text from text inputs 不兼容的操作数类型字符串和字符语法错误 - Incompatible operand types String and char syntax error 不兼容的类型 char 和 boolean - incompatible types char and boolean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM