如何在2D字符数组java中获取用户输入
我正在尝试从2d字符数组中使用获取输入,其中输出应如下所示: 110 1_0 十一,_ _十一, 0__ 这可以有多达2^n的组合,其中n也是用户输入。如何创建此输出如何在2D字符数组java中获取用户输入,java,Java,我正在尝试从2d字符数组中使用获取输入,其中输出应如下所示: 110 1_0 十一,_ _十一, 0__ 这可以有多达2^n的组合,其中n也是用户输入。如何创建此输出 public static void main (String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter Value i: "); int i = sc.nextInt(); int j =(int)
public static void main (String args[])
{ Scanner sc = new Scanner(System.in);
System.out.println("Enter Value i: ");
int i = sc.nextInt();
int j =(int) Math.pow(2,i);
char[][]array = new char[i][j];
for (int k=0;k<i;k++)
for (int s=0;s<j;s++)
{ array[k][s]= ?; //i am stuck here
}
publicstaticvoidmain(字符串参数[])
{Scanner sc=新扫描仪(System.in);
System.out.println(“输入值i:”);
int i=sc.nextInt();
int j=(int)Math.pow(2,i);
char[][]数组=新的char[i][j];
对于(int k=0;k
获取二维字符数组的步骤如下:-
[[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]]
Scanner scan=新的扫描仪(System.in);
字符输入阵列[][]=新字符[行][cols];
对于(int i=0;i
为什么输出应该是这样?我不明白为什么输出中有uu!这是真值表中的一个不在乎值。你说你要得到输入。我们为什么要关心输出?你不需要扫描仪来做这么简单的事情。读取2d数组的数据与读取一维数组的数据有什么不同?我需要你t对于我的另一段代码,我需要行和列的轨迹。如果代码周围有一些文本和更好的缩进,这将更有用
4 // no. of rows
5 // no. of columns
10100
10111
11111
10010
[[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]]
Scanner scan=new Scanner(System.in);
char inputArray[][] = new char[rows][cols];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
inputArray[i][j] = scan.next().charAt(0);
}
}