In this post, we will understand **what is Nelson number?** and ** how to check whether a number is Nelson in Java?**

In cricket, the number 111 is sometimes called “

a Nelson” after Admiral Nelson, who allegedly only had “One Eye, One Arm, One Leg” near the end of his life. This is, in fact, inaccurate—Nelson never lost a leg.

So the number 111 is called a nelson number and multiple of nelson are called double Nelson (222), triple Nelson (333) and so on.

We need to note that multiples of 111 are Nelson numbers e.g 111, 222, 333, 444, 555, 666, 777, 888 and 999. Not any other number which is divisible by 111.

Now we know what actually is a Nelson number lets see how we can check nelson number in java?

We need to use if-else for every multiple of 111, if the input number satisfies any condition then we output that the given number is a nelson number.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter a number"); int n=in.nextInt(); if(n==111 || n==222 || n==333 || n==444 || n==555 || n==666 || n==777 || n==888 || n==999){ System.out.println("Nelson Number"); } else { System.out.println("Not a Nelson Number"); } } } |

**output**

That’s all for the Nelson number if you have any suggestions or doubts then please comment below.