Reputation: 43
I'll try to explain what I got and what I need easily and clearly.
I have an array of 2 dimensions, making a board of char elements. I have to do a shot from the bottom showing it with '·'. The shot goes from the bottom, (a.length-1) to the top (0), doing bounces on the walls, depending on the shot direction.
if (dirDisp == 3){
for(int x = 3, y = 0; x < 5 & y < 2; x++, y++) {
if(a[(a.length-1) - y][(a[x].length-1) / 2 + x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 + x] = '·';
}
for(int x = 0, y = 1; x < 9 & y < 11; x++, y++) {
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
}
for(int x = 0, y = 9; x < 5 & y < 14; x++, y++) {
if(a[(a.length-1) - y][x] == EMPTY)
a[(a.length-1) - y][x] = '·';
}
}
I've put above the code for shot direction = 3. EMPTY constant is ' '. The thing is that I also hace other char in the array, like 'a','b',etc.
What I want , is to stop the loops if there is not an EMPTY. What it does actually, is that:
g g b g g y y r r
y o y a r y g o b
g o r a b r a a b
g y o a y a g o b
g a b b b o o b g
·
·
r r r r r r r r r
·
·
·
·
·
·
The shot must stop when it reaches the first char different to EMPTY. I've tried to use break and continue. Also the use of firstLoop:{}. I've also tried to use a boolean in each part of the loops, but I havent got it to work. I need a little bit of help.
If something is not clear just ask.
PD: The shot, has 3 'for' loops, the first is to fill the array from the bottom to the first wall, the second, for the space between wall and wall, and the third, for the opposite wall to the top. PD2: The 'r' line is there for you to see what actually happens.
After Using Boolean:
a b a b y a r y y
y a o y g r o g g
g o y o a y y a y
y o a a g o o b a
o o r a o r g y y
r r r r r r r r r
·
·
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Stack;
public class BobbleTexto {
public static Scanner sc = new Scanner(System.in);
public static char RED = 'r';
public static char GREEN = 'g';
public static char BLUE = 'b';
public static char ORANGE = 'o';
public static char YELLOW = 'y';
public static char GRAY = 'a';
public static char PURPLE = 'p';
public static char EMPTY = ' ';
public static char IZQUIERDA = 'A';
public static char DERECHA = 'D';
public static char DISPARO = 'S';
public static char SALIR = 'Q';
public static char [][] generarTablero (){
char [][] a = new char [14][9];
for (int x = 0; x < a.length; x++){
for (int y = 0; y < a[x].length;y++){
a [x][y] = EMPTY;
}
}
for(int x = 0; x < 5; x++){
for(int y = 0; y < a[y].length; y++){
a[x][y] = generarBurbuja();
a[7][y] = RED;
}
}
return a;
}
public static char [][] limpiarTablero (char [][] a){
for (int x = 0; x < a.length; x++){
for (int y = 0; y < a[x].length;y++){
if (a [x][y] == '·')
a[x][y] = EMPTY;
}
}
return a;
}
public static void imprimirDisparo (char [][] a,int dirDisp,char Burbuja){
if (dirDisp == 1){
for(int x = 1, y = 0; x < 5 & y < 4; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 + x] == EMPTY){
a[(a.length-1) - y][(a[x].length-1) / 2 + x] = '·';
}
else{
break;
}
}
for(int x = 0, y = 3; x < 9 & y < 11; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY){
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
}
else{
}
}
for(int x = 0, y = 11; x < 4 & y < 14; x++, y++){
if(a[(a.length-1) - y][x] == EMPTY){
a[(a.length-1) - y][x] = '·';
}
else{
break;
}
}
}
if (dirDisp == 2){
for(int x = 2, y = 0; x < 5 & y < 3; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 + x] == EMPTY){
a[(a.length-1) - y][(a[x].length-1) / 2 + x] = '·';
}
else {
}
}
for(int x = 0, y = 2; x < 9 & y < 11; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY){
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
}
else {
}
}
for(int x = 0, y = 10; x < 4 & y < 14; x++, y++){
if(a[(a.length-1) - y][x] == EMPTY){
a[(a.length-1) - y][x] = '·';
}
else {
}
}
}
if (dirDisp == 3){
boolean foundObstacle = false;
for(int x = 3, y = 0; x < 5 & y < 2 && !foundObstacle; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 + x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 + x] = '·';
else {
foundObstacle = true;
break;
}
}
if(!foundObstacle) {
for(int x = 0, y = 1; x < 9 & y < 11 && !foundObstacle; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
else {
foundObstacle = true;
break;
}
}
}
if(!foundObstacle) {
for(int x = 0, y = 9; x < 5 & y < 14 && !foundObstacle; x++, y++){
if(a[(a.length-1) - y][x] == EMPTY)
a[(a.length-1) - y][x] = '·';
else break;
}
}
}
if (dirDisp == 4){
for(int x = 4, y = 0; x < 5 & y < 1; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 + x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 + x] = '·';
}
for(int x = 0, y = 0; x < 9 & y < 11; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
}
for(int x = 0, y = 8; x < 6 & y < 14; x++, y++){
if(a[(a.length-1) - y][x] == EMPTY)
a[(a.length-1) - y][x] = '·';
}
}
if (dirDisp == 0) {
for (int x = 0; x < a.length; x++)
if(a[x][(a[x].length - 1) / 2] == EMPTY)
a[x][(a[x].length - 1) / 2] = '·';
}
if (dirDisp == -1){
for(int x = 1, y = 0; x < 5 & y < 4; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 - x] = '·';
}
for(int x = 1, y = 3; x < 11 & y < 12; x++, y++){
if(a[(a.length-1) - y][x-1] == EMPTY)
a[(a.length-1) - y][x-1] = '·';
}
for(int x = 0, y = 11; x < 4 & y < 14; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
}
}
if (dirDisp == -2){
for(int x = 2, y = 0; x < 5 & y < 4; x++, y++){
if( a[(a.length-1) - y][(a[x].length-1) / 2 - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 - x] = '·';
}
for(int x = 1, y = 2; x < 10 & y < 12; x++, y++){
if(a[(a.length-1) - y][x-1] == EMPTY)
a[(a.length-1) - y][x-1] = '·';
}
for(int x = 0, y = 10; x < 4 & y < 14; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
}
}
if (dirDisp == -3){
for(int x = 3, y = 0; x < 5 & y < 4; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 - x] = '·';
}
for(int x = 1, y = 1; x < 10 & y < 12; x++, y++){
if(a[(a.length-1) - y][x-1] == EMPTY)
a[(a.length-1) - y][x-1] = '·';
}
for(int x = 0, y = 9; x < 5 & y < 14; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
}
}
if (dirDisp == -4){
for(int x = 4, y = 0; x < 5 & y < 4; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 - x] = '·';
}
for(int x = 1, y = 0; x < 10 & y < 12; x++, y++){
if(a[(a.length-1) - y][x-1] == EMPTY)
a[(a.length-1) - y][x-1] = '·';
}
for(int x = 0, y = 8; x < 6 & y < 14; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
}
}
for (int x = 0; x < a.length; x++){
System.out.println();
for (int y = 0; y < a[x].length; y++){
System.out.print(" "+a [x][y]+" ");
}
}
System.out.println("\nDirección de disparo ["+dirDisp+"]");
System.out.println("Burbuja ["+Burbuja+"]");
}
public static int getDirDisp(){
int dirDisp = sc.nextInt();
while (dirDisp < -4 || dirDisp > 4){
System.out.println("Introduzca una dirección de disparo válida(-1,-2,-3,0,1,2,3)");
dirDisp = sc.nextInt();
}
return dirDisp;
}
public static char generarBurbuja(){
char burbuja = EMPTY;
int azar = (int) (Math.random() * 6);
switch (azar){
case 0 : burbuja = RED; break;
case 1 : burbuja = GREEN; break;
case 2 : burbuja = BLUE; break;
case 3 : burbuja = ORANGE; break;
case 4 : burbuja = YELLOW; break;
case 5 : burbuja = GRAY; break;
case 6 : burbuja = PURPLE; break;
}
return burbuja;
}
public static char obtenerAccionJugador (){
System.out.println("Acción?");
String aux = sc.next();
char accion = aux.charAt(0);
while (accion != IZQUIERDA && accion != DERECHA && accion != DISPARO && accion != SALIR){
System.out.println("Introduzca una acción válida:");
aux = sc.next();
accion = aux.charAt(0);
}
System.out.println("***************************");
return accion;
}
public static void obtenerTrayectoria (char [][] a){
System.out.println("Posiciones:");
for (int x = 0; x < a.length; x++){
for (int y = 0; y < a[x].length;y++){
if(a [x][y] == '·'){
Posicion pos = new Posicion(x,y);
ArrayList<Posicion> aListPos = new ArrayList<Posicion>();
aListPos.add(pos);
for(Posicion ii : aListPos){
System.out.println("(" + pos.getFila() + "," + pos.getColumna()+")");
}
}
}
}
}
public static char [][] realizarDisparo (char [][] a,char Burbuja){
int c [] = new int [a.length];
int w = 0;
for (int x = 0; x < a.length; x++){
for (int y = 0; y < a[x].length;y++){
if (a [x][y] == '·'){
w++;
c [w]= x;
}
if(a[c[1]][y] == '·'){
a[c[1]][y] = Burbuja;
}
}
}
return a;
}
public static int moverDerecha (int dirDisp, char [][] a){
if(dirDisp == -4)
dirDisp = -3;
else if (dirDisp == -3)
dirDisp = -2;
else if (dirDisp == -2)
dirDisp = -1;
else if (dirDisp == -1)
dirDisp = 0;
else if (dirDisp == 0)
dirDisp = 1;
else if (dirDisp == 1)
dirDisp = 2;
else if (dirDisp == 2)
dirDisp = 3;
else if(dirDisp == 3)
dirDisp = 4;
return dirDisp;
}
public static int moverIzquierda (int dirDisp, char [][] a){
if(dirDisp == 4)
dirDisp = 3;
else if (dirDisp == 3)
dirDisp = 2;
else if (dirDisp == 2)
dirDisp = 1;
else if (dirDisp == 1)
dirDisp = 0;
else if (dirDisp == 0)
dirDisp = -1;
else if (dirDisp == -1)
dirDisp = -2;
else if (dirDisp == -2)
dirDisp = -3;
else if(dirDisp == -3)
dirDisp = -4;
else{}
return dirDisp;
}
public static boolean existenBurbujas (char [][] a){
boolean result = true;
int contadorBurbujas = 0;
for (int x = 0; x < a.length; x++){
for (int y = 0; y < a[x].length;y++){
if(a [x][y] != EMPTY){
contadorBurbujas++;
}
}
}
if(contadorBurbujas > 0){
return true;
}
return result;
}
public static void borrarBurbujasAgrupadas(char [][] b, Posicion p) {
if(b[p.fila][p.columna] != EMPTY)
vecinos(b, p.fila, p.columna, b[p.fila][p.columna]);
}
private static void vecinos(char [][] b, int i_comienzo, int j_comienzo, char destino) {
Stack<Integer> ic = new Stack<Integer>();
Stack<Integer> jc = new Stack<Integer>();
ic.add(i_comienzo);
jc.add(j_comienzo);
int t = 0;
boolean [][] visitados = new boolean[b.length][b[0].length];
while( !ic.isEmpty() ) {
int i = ic.pop();
int j = jc.pop();
visitados[i][j] = true;
t++;
if(j-1 >= 0) {
if(b[i][j-1] == destino && !visitados[i][j-1]) {
ic.push(i);
jc.push(j-1);
}
}
if(j+1 < b[0].length) {
if(b[i][j+1] == destino && !visitados[i][j+1]) {
ic.push(i);
jc.push(j+1);
}
}
if(i-1 >=0) {
if(b[i-1][j] == destino && !visitados[i-1][j]) {
ic.push(i-1);
jc.push(j);
}
}
if(i+1 < b.length) {
if(b[i+1][j] == destino && !visitados[i+1][j]) {
ic.push(i+1);
jc.push(j);
}
}
if(j-1 >=0 && i-1 >=0) {
if(b[i-1][j-1] == destino && !visitados[i-1][j-1]) {
ic.push(i-1);
jc.push(j-1);
}
}
if(j+1 < b[0].length && i-1 >= 0 ) {
if(b[i-1][j+1] == destino && !visitados[i-1][j+1]) {
ic.push(i-1);
jc.push(j+1);
}
}
if(j-1>=0 && i+1<b.length) {
if(b[i+1][j-1] == destino && !visitados[i+1][j-1]) {
ic.push(i+1);
jc.push(j-1);
}
}
if(j+1<b[0].length && i+1<b.length) {
if(b[i+1][j+1] == destino && !visitados[i+1][j+1]) {
ic.push(i+1);
jc.push(j+1);
}
}
}
if(t >= 3)
for(int i=0; i<visitados.length; i++)
for(int j=0; j<visitados[i].length; j++)
if(visitados[i][j])
b[i][j] = EMPTY;
}
public static void jugar (){
Posicion p = new Posicion();
char [][] a = generarTablero();
System.out.println("Introduzca la dirección de disparo(-1,-2,-3,-4,0,1,2,3,4)");
int dirDisp = getDirDisp();
char Burbuja = generarBurbuja();
imprimirDisparo(a,dirDisp,Burbuja);
char accion = obtenerAccionJugador();
while(true){
if (accion == IZQUIERDA){
dirDisp = moverIzquierda(dirDisp,a);
limpiarTablero(a);
imprimirDisparo(a,dirDisp,Burbuja);
accion = obtenerAccionJugador();
}
else if(accion == DERECHA) {
dirDisp = moverDerecha(dirDisp,a);
limpiarTablero(a);
imprimirDisparo(a,dirDisp,Burbuja);
accion = obtenerAccionJugador();
}
else if(accion == DISPARO){
realizarDisparo(a,Burbuja);
borrarBurbujasAgrupadas(a,p);
Burbuja = generarBurbuja();
imprimirDisparo(a,dirDisp,Burbuja);
obtenerTrayectoria(a);
accion = obtenerAccionJugador();
}
else if (accion == SALIR){
System.out.println("GAME OVER");
}continue;
}
}
public static void main (String[] args){
jugar();
}
}
The other class with object
public class Posicion {
int fila;
int columna;
public Posicion(int fila,int columna) {
this.fila = fila;
this.columna = columna;
}
public int getFila(){
return this.fila;
}
public int getColumna(){
return this.columna;
}
public Posicion(){}
After all your answers I've done a new method to shot, much easier than the first one, with while loops and more constant names to make it easy to understand.
The Position class is still the same.
I'll put here the code with the positive shoot direction:
public static void getTrayectory (char [][] a,int shootDirection){
int x = 0, y = 0;
START = ((RIGHT_WALL)/2) + shootDirection;
a [BOTTOM][START] = SHOT;
if(shootDirection > 0){
while (!isOut(BOTTOM-x,START+y) && emptyCell(BOTTOM-x,START+y)){
b [BOTTOM - x][START + y] = SHOT;
x++; y++;
}
y = 0; x=x-1;
while (!isOut(BOTTOM-x,RIGHT_WALL-y) && emptyCell(BOTTOM-x,RIGHT_WALL-y)){
b [BOTTOM-x][RIGHT_WALL-y] = SHOT;
x++; y++;
}
y = 0; x=x-1;
while (!isOut(BOTTOM-x,LEFT_WALL+y) && emptyCell(BOTTOM-x,LEFT_WALL+y)){
b [BOTTOM-x][LEFT_WALL+y] = SHOT;
x++; y++;
}
y = 0;
while (!isOut(BOTTOM-x,RIGHT_WALL-y) && emptyCell(BOTTOM-x,RIGHT_WALL-y)){
b [BOTTOM-x][RIGHT_WALL-y] = SHOT;
x++; y++;
}
}
}
public static char [][] b = new char [25][9];
public static char EMPTY = '-';
public static char SHOT = 'x';
public static Scanner sc = new Scanner(System.in);
public static int shootDirection;
public static int BOTTOM = b.length - 1;
public static int RIGHT_WALL = b[0].length - 1;
public static int LEFT_WALL = 0;
public static int TOP = 0;
public static int CENTER = ((RIGHT_WALL)/2);
public static int START = ((RIGHT_WALL)/2) + shootDirection;
public static void fill (char [][] b){
for (int x = 0; x < b.length; x++){
for (int y = 0; y < b[x].length;y++){
b [x][y] = EMPTY;
b [10][y] = 'A';
}
}
}
public static void show (char [][] b){
for (int x = 0; x < b.length; x++){
System.out.println();
for (int y = 0; y < b[x].length; y++){
System.out.print(" "+b [x][y]+" ");
}
}
}
public static boolean isOut (int x,int y){
if(x < TOP)return true;
if(y > RIGHT_WALL)return true;
if(y < LEFT_WALL)return true;
return false;
}
static boolean emptyCell(int x, int y){
return b [x-1][y] == EMPTY;
}
The thing is, that it works, but, there is a mistake in the emptyCell method. It returns b [x-1][y] == EMPTY, because if I use return b[x][y] it gets an OutOfBounds error. Due to the x-1, the loop stops one row before it should stop, and I dont know how to modify it to make it work properly.
The other thing is, that I would like to do an easier method, but even with the little example below, I cant figure out how to do it with my constants. I hope you can do it for me, it must be easy but I dont know :S With the isOut method and the emptyCell method, the answer must be near. Thank you and sorry for this long thread.
Upvotes: 3
Views: 224
Reputation: 29213
The solution that's closest to what you have, as far as I understand the code, is to put an else
at the EMPTY
checks and, in there, tell it to break
from the first loop that may be interrupted. Then, set a variable that tells it to stop, then make the rest for
loops conditional for that variable, so that it doesn't pick from there.
So, it could go like this (but please remember that the following is a bad workaround and the overall structure of this code should be improved immediately after):
if (dirDisp == 3){
boolean foundObstacle = false;
for(int x = 3, y = 0; x < 5 & y < 2; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 + x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 + x] = '·';
else {
foundObstacle = true;
break;
}
}
if(!foundObstacle) {
for(int x = 0, y = 1; x < 9 & y < 11; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
else {
foundObstacle = true;
break;
}
}
}
if(!foundObstacle) {
for(int x = 0, y = 9; x < 5 & y < 14; x++, y++){
if(a[(a.length-1) - y][x] == EMPTY)
a[(a.length-1) - y][x] = '·';
else break;
}
}
}
Once that solves your problem, consider some changes to your code, because first and foremost it's considered bad practice to use a for
loop if you know that the loop is going to end prematurely. We usually use a while
loop in these cases. Second, it's not a good idea to hard code such things. You could come up with an algorithm that does the job for any given direction, once you get the hang of this.
Hope this helps.
Edit:
if (dirDisp == 3){
boolean foundObstacle = false;
for(int x = 3, y = 0; x < 5 & y < 2 && !foundObstacle; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) / 2 + x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) / 2 + x] = '·';
else {
foundObstacle = true;
break;
}
}
if(!foundObstacle) {
// At its first iteration, this loop finds the '·' symbol placed by the previous one.
// So I've made it start from the second.
for(int x = 1, y = 2; x < 9 & y < 11 && !foundObstacle; x++, y++){
if(a[(a.length-1) - y][(a[x].length-1) - x] == EMPTY)
a[(a.length-1) - y][(a[x].length-1) - x] = '·';
else {
foundObstacle = true;
break;
}
}
}
if(!foundObstacle) {
for(int x = 0, y = 9; x < 5 & y < 14 && !foundObstacle; x++, y++){
if(a[(a.length-1) - y][x] == EMPTY)
a[(a.length-1) - y][x] = '·';
else break;
}
}
}
Keep in mind that the reason you're having trouble debugging this is, as someone else suggested, that the code is very obscure. No matter how experienced one is, this is a very difficult thing to debug.
That's why everyone suggests that we should write clean code. Remember, everybody makes mistakes. Once you understand how to write a program in a language (and you personally do, apparently), what makes the most difference is how well you understand the code on your own, so that you can see your mistakes more easily. Never think that you understand a piece of code just because you've written it yourself. Make lots of variables, give them meaningful names, break your program in parts, make lots of types that correspond to the entities your program has to deal with, give them meaningful names too, locate repeated code patterns, turn them into functions/methods (with or without parameterized parts) and give them meaningful names as well.
Even if you can't find your errors at that point, it will at least be easier for others to help you. ;)
Upvotes: 1
Reputation: 17435
if your break condition is complex, I suggest using a while loop instead. Using nice method names will also make your code more readable.
while (!outOfBounds(x,y) && emptyCell(x,y) {
a[x][y] = '.';
moveCursor(direction);
}
...
boolean emptyCell(int x, int y){
return a[x][y] == EMPTY;
}
boolean outOfBounds(int x, int y){
if (x<0) return true;
if (y<0) return true;
if (x>LIMIT_X) return true;
if (y>LIMIT_Y) return true;
return false;
}
void moveCursor(direction){
if (direction==DOWN_RIGHT){
x++;
y++;
if (x > X_LIMIT){
x-=2;
direction = DOWN_LEFT;
}
...
}
Upvotes: 1
Reputation: 7347
I just wrote this tiny method, which is doing what you want. but it gets filled a rnd char array. see my break condition
private void shot() {
char charArray[][] = new char[100][20];
Random r = new Random();
for(int i = 0;i<charArray.length;++i) {
for(int j = 0;j<charArray[0].length;++j) {
if(r.nextInt(5) == 0) {
charArray[i][j] = (char) (r.nextInt(26)+65);
}
}
}
boolean shotRight = false;
for(int i = charArray.length-1,j = charArray[0].length-1;i>0;--i) {
System.out.println(i + " " + j);
// break condition
if(charArray[i][j] != '\u0000') break;
if(shotRight) {
charArray[i][j] = '.';
++j;
}
else {
charArray[i][j] = '.';
--j;
}
if(j <= 0) {
shotRight = true;
}
if(j >= charArray[0].length-1) {
shotRight = false;
}
}
for(int i = 0;i<charArray.length;++i) {
for(int j = 0;j<charArray[0].length;++j) {
System.out.print(((charArray[i][j] == '\u0000') ? " ":charArray[i][j] + " ") + " ");
}
System.out.println();
}
}
it does break, becuase the default value of a char = '\u0000'
Upvotes: 0