[英]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.