【发布时间】:2015-05-16 15:59:35
【问题描述】:
我有一个关于将数组中的字符与特定输入(字符串)进行比较的问题。
我似乎在它声明的行有问题:String[] oneRow = alphabet[i];
package MemoryGame;
导入 java.util.Scanner;
公共类记忆{
/*
* array list of the alphabet.
*/
char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
/*
* Constructor
*/
public Memory(){
/*
* Scanner initiation for input end-user.
*/
System.out.println("What is the first letter of you name? ");
Scanner scan = new Scanner(System.in);
String letter = scan.nextLine();
String s = scan.nextLine();
/*
* Comparing Input with array
*/
String[] matchedRow;
for(int i=0; i<alphabet.length; i++)
{
String[] oneRow = alphabet[i];
if(oneRow[0].equals(letter))
{
matchedRow = oneRow;
break;
}
}
for(int i=0; i<matchedRow.length; i++)
{
System.out.println(matchedRow[i]);
}
}
public static void main(String[] args) {
Memory memory = new Memory();
}
Eclipse 说:
类型不匹配:无法从 char 转换为 String[]
感谢您的帮助!
M
【问题讨论】:
-
您告诉我们您遇到了问题。介意描述问题吗?错误信息,什么?
标签: java string char type-conversion