attack range

재피터노트북·2022년 8월 28일
0

문제


풀이 코드

import java.util.Scanner;
public class Main{
    public static void main(String[] args){

       // Please Enter Your Code Here
       Scanner s = new Scanner(System.in);
       int num1 = s.nextInt();
       int num2 = s.nextInt();
       int num3 = s.nextInt();
       int num4 = s.nextInt();
       int[][] arr = new int[num1][num1];
       int xNum;
       int yNum;
       
       for (int i=1;i<=num1;i++){
         for (int j=1;j<=num1;j++){
           xNum = i - num2;
           yNum = j - num3;
           
           if (xNum < 0) xNum *= -1;
           if (yNum < 0) yNum *= -1;
           
           if (i == num2 && j == num3){
             System.out.print("x" + " ");
           }
           else if (xNum + yNum <= num4 && xNum + yNum > 0){
             System.out.print(xNum + yNum + " ");
           }
           else {
             System.out.print(0 + " ");
           }
         }
         System.out.println();
       }

       
       
       
    }
}
profile
난 이 재 선

0개의 댓글