Menu
Question Index
...

What will be the output of the following program?

public class CanHorseKillPawn {
    static int count = 0;
    public static void main(String[] args) {
        canHorseKill('A', 2, 'B', 3);
        canHorseKill('A', 2, 'B', 4);
        canHorseKill('A', 2, 'C', 3);
        canHorseKill('B', 4, 'H', 7);
        canHorseKill('C', 3, 'A', 2);
        canHorseKill('C', 3, 'A', 4);
    }
    private static void canHorseKill(char horseRow, int horseColumn, char pawnRow, int pawnColumn) {
        boolean result = true;
        result &= (Math.abs(horseRow - pawnRow) == 2 && Math.abs(horseColumn - pawnColumn) == 1);
        result |= (Math.abs(horseRow - pawnRow) == 1 && Math.abs(horseColumn - pawnColumn) == 2 && count++ < 10);
        System.out.print(count + "" + (result ? 'K' : 'N'));
    }
}


0N1N1K1N1K1K
1N2K3K4N5K6K
0N1K1K1N1K1K
Some other output or Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Math Class - java.lang.Math

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App