0

자바에서 배열을 처음 사용합니다. 내가 이것을 보여주고 싶었다 경우문자 배열 앞에 /를 추가하십시오.

0 .... 
    1 .... 
    2 ....  
    3 .... 
    4 .... 

:

.... 
    .... 
    .... 
    .... 
    ....  is a 2-d char array called char[][] squares. 

가 어떻게 사각형 배열하기 전에 번호를 추가하는 방법은 무엇입니까?

그리고 하나의 번호 (예 : 3)를 선택하고 3의 바로 옆에 ">"를 추가하려면 어떻게해야합니까?

0 .... 
    1 .... 
    2 ....  
    3>.... 
    4 .... 

답변

0
for(int y = 0; y< array.lenght;y++) { 
    for(int x = 0; x< array[y].lenght;x++) { 
     System.out.println(array[y][x]); 
    } 

    System.out.println(); 
} 
0

내가 질문에 이런 종류의 허용 있는지 확실하지 않습니다이

private void print_array(char[][] squares, int selectedIndex){ 
    for(int i =0;i<squares.length;i++){ 
     System.out.print(i); 
     if(i == selectedIndex){ 
      System.out.print(">"); 
     } 
     for(int j = 0;j<squares[i].length;j++){ 
      System.out.print(squares[i][j]); 
     } 
     System.out.println(); 
    } 
} 
0

을 시도하지만, 여기에 대한 대답입니다 : 그럼, 내가 원하는 것입니다. chars [m] [n] 배열이 있다고 가정 해 보겠습니다. 과 희망은 X 선 전> 인쇄

for(int i = 0; i < m; i++) 
{ 
     String s = i+""; 
     if(i == x) s = s + ">"; 
     else  s = s+ " "; 
     s = s + new String(chars[i]) 
     System.out.println(s); 
} 
0

귀하의 질문은 오히려 비밀입니다하지만 난 그것을 샷주지 :

class Whatever { 

public static void Main(String[] args) { 

char[][] squares = new char[5][2]; 

/* 
Here goes your code to assign values to the array 
*/ 

for(int i:=0, i<5; ++i) { 
    System.out.println(i); 
    if (i==3) { 
     System.out.print("> "); 
    } else { 
     System.out.print(" ") 
    } 
    for(j:=0; j<2; ++j) { 
     System.out.println(aquares[i][j]); 
    } 
} 
} 
관련 문제