صفحه شطرنجی در محیط کنسول

سوال

باسلام و ادب دوست داشتم کدی بنویسم که مانند صفحه شطرنج در کنسول چاب شود ولی نتوانستم.یک شخصی زد ولی من میخواستم استادی به من توضیح دهد

package test;

import java.io.IOException;
import java.util.Scanner;

public class Main {

public static final class Place {
boolean isLight=false;
}

public static final void main(String[] args)throws IOException {
int a = (new Scanner(System.in)).nextInt();
int total = a*a;

Place places[] = new Place[total];
for(int i=0;i<total;i++) {
int j=i;
int row = (i) / a;
if(row % 2==0)
j=j+1;
Place p=new Place();
if ( j %2 ==0 )
p.isLight=true ;
places [i]=p;

}

for (int i = 0; i< places.length ; i++ ) {
Place p = places [i];
System.out.print(“t” + (p.isLight ? “-” : “+”));
float x = (i + 1) % a;
if(x == 0)
System.out.println();

}

}

}

0
09102937177 3 سال 0 پاسخ ها 232 دیده شده 0

ارسال یک پاسخ