import java.io.*;
import java.util.*;public class MazeDemo {
Scanner scan = null;
private int width,height;
char a[][]; public void InitMaze(){
scan = new Scanner(System.in);
System.out.println("Please input the width and height");
width = scan.nextInt();
height = scan.nextInt();
System.out.println("width: "+width+" height: "+height);
a = new char[height][width];
System.out.println("please input the context:");
String s = scan.next();
for(int i = 0; i < height; i++)
{
s = scan.nextLine();
String[] a1 = s.split(" ");
for(int j=0;j<a1.length;j++){
char aa = a1[j].charAt(0);
a[i][j] = aa;
}
}
}
public void display(){
for(int i = 0; i <height; i++){
for(int j = 0; j <a.length; j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
}
public MazeDemo() {
}
public static void main(String...args){
MazeDemo maze = new MazeDemo();
maze.InitMaze();
maze.display();
}}程序想实现的功能:
input
3 4
1 1 0 0
1 0 1 1
0 0 1 1
output
1 1 0 0
1 0 1 1
0 0 1 1通过 输入 width and height 开辟确定大小的内存空间
然后再输入 矩阵 ,矩阵输入的过程中换行了!!
再回显矩阵
求解答,急急
import java.util.*;public class MazeDemo {
Scanner scan = null;
private int width,height;
char a[][]; public void InitMaze(){
scan = new Scanner(System.in);
System.out.println("Please input the width and height");
width = scan.nextInt();
height = scan.nextInt();
System.out.println("width: "+width+" height: "+height);
a = new char[height][width];
System.out.println("please input the context:");
String s = scan.next();
for(int i = 0; i < height; i++)
{
s = scan.nextLine();
String[] a1 = s.split(" ");
for(int j=0;j<a1.length;j++){
char aa = a1[j].charAt(0);
a[i][j] = aa;
}
}
}
public void display(){
for(int i = 0; i <height; i++){
for(int j = 0; j <a.length; j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
}
public MazeDemo() {
}
public static void main(String...args){
MazeDemo maze = new MazeDemo();
maze.InitMaze();
maze.display();
}}程序想实现的功能:
input
3 4
1 1 0 0
1 0 1 1
0 0 1 1
output
1 1 0 0
1 0 1 1
0 0 1 1通过 输入 width and height 开辟确定大小的内存空间
然后再输入 矩阵 ,矩阵输入的过程中换行了!!
再回显矩阵
求解答,急急
Scanner scan = null;
private int width,height;
String a[][]; public void InitMaze(){
scan = new Scanner(System.in);
System.out.println("Please input the width and height");
width = scan.nextInt();
height = scan.nextInt();
System.out.println("width: "+width+" height: "+height);
a = new String[height][width];
System.out.println("please input the context:");
String s = scan.nextLine();
for(int i = 0; i < height; i++)
{
s = scan.nextLine();
String[] a1 = s.split(" ");
a[i] = a1;
}
}
public void display(){
for(int i = 0; i <height; i++){
for(int j = 0; j <width; j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
}
public MazeDemo() {
}
public static void main(String...args){
MazeDemo maze = new MazeDemo();
maze.InitMaze();
maze.display();
}}