java - 数组不改变值java
问题描述
您好,如何更改 char 数组中的索引值?我尝试了通常的方式 array[][] = ""; 但是当我打印它时,它仍然显示原始的硬编码数组。
这是主要的
public static void main(String args[]){
int seatChoice = 0,seatCol = 0;
String seat, type;
char[][] airplane = {{'*','*','*','*','*','*'},{'*','*','*','*','*','*'},{'*','*','*','*','*','*'},
{'*','*','*','*','*','*'},{'*','*','*','*','*','*'},{'*','*','*','*','*','*'},
{'*','*','*','*','*','*'},{'*','*','*','*','*','*'},{'*','*','*','*','*','*'},
{'*','*','*','*','*','*'},{'*','*','*','*','*','*'},{'*','*','*','*','*','*'},
{'*','*','*','*','*','*'}};
menu(airplane);
System.out.print("Please input ticket type: ");
type = input.nextLine();
System.out.print("Please input desired seat: ");
seat = input.nextLine();
seatChoice = reservation(seat) - 1;
if(seat.charAt(1) == 'A')
seatCol = 0;
if(seat.charAt(1) == 'B')
seatCol = 1;
if(seat.charAt(1) == 'C')
seatCol = 2;
if(seat.charAt(1) == 'D')
seatCol = 3;
if(seat.charAt(1) == 'E')
seatCol = 4;
if(seat.charAt(1) == 'F')
seatCol = 5;
airplane[seatChoice][seatCol] = 'X';
System.out.println(seatChoice);
System.out.println(seatCol);
System.out.println(airplane[seatChoice][seatCol]);
showSeat(airplane);
}
这些是其他方法
public static int reservation(String seat){
int seatChoice = 0;
seatChoice = Character.getNumericValue(seat.charAt(0));
System.out.println("Your seat has been reserved.");
return seatChoice;
}
public static void showSeat(char[][] airplane){
int rows = 13, seats = 6, numRow = 1;
System.out.println(" A B C D E F ");
System.out.println();
for (int count = 0; count < rows; count++){
System.out.print("ROW " + numRow + " ");
for (int count2 = 0; count2 < seats; count2++){
System.out.print(" " + airplane[rows-1][seats-1] + " ");
}
numRow++;
System.out.println();
}
}
解决方案
rows
和seats
的价值
System.out.print(" " + airplane[rows-1][seats-1] + " ");
不变,它们总是基于int rows = 13, seats = 6,
尝试使用count
和count2
推荐阅读
- javascript - 空调功能
- css - 在引导程序 4 中关闭折叠的导航栏后,导航栏项目仍然可见一段时间
- python - 无法写入 TensorArray 索引,因为值形状与 TensorArray 的推断元素形状不兼容
- javascript - console.log 返回 [object Object]
- php - 卡在通知系统上
- node.js - 无法在 Express.js 中获取处理 request.params 的服务器结果
- android - Android中的上下文是复杂策略设计模式的实现吗?
- python - 循环中的numpy column_stack
- swift - 如何使用 UITabBarController 实现此布局
- excel - 有没有办法在案例结果之后在此代码中实现“Msgbox”?