在Java中查找char数组中的char元素
我在字符数组中查找特定字符元素时遇到问题。 我知道如何使用intigers,但不知道如何使用char元素。 这是我的整数搜索代码。 谢谢
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
st = br.readLine();
searchKey = Integer.parseInt(st);
} catch (Exception e) {
System.out.println("input-output error");
return;
}
for (i = 0; i < B.length; i++) {
boolean found = false;
if (B[i] == searchKey) {
found = true;
}
if (found) {
System.out.println(searchKey + " Value is found pozicija " + (i + 1));
c++;
}
if (c == 0 && i == B.length - 1) {
System.out.println("Value " + searchKey + " not found...!");
}
}
c = 0;
break;
更新:
char A[][] = new char [10][10]; // Matricas inicializaacija
char B[] = new char [55]; // Vektora inicializaacija
char C[] = new char [10]; // Vektora inicializaacija
char D[] = new char [10]; // Vektora inicializaacija
我只有数组A[]。这是二维数组,里面充满了随机数,还有数组B[],在我们大学里叫做向量数组,所有的A[i][j]个数字都显示在一行“Print”中。 现在,用户应该输入他想在B数组中找到的字符,并使用BufferReader帮助程序输出:数组中字符的位置,如果未找到,则输出“Value not found”
# 1 楼答案
试试这个例子: