Strontio Number in Java
In this section, we will learn what is a strontio number and also create Java programs to check if the given number is strontio. The strontio number program frequently asked in Java coding tests and academics.
Strontio numbers are those four digits numbers when multiplied by 2 give the same digit at the hundreds and tens place. Remember that the input number must be a four-digit number.
Strontio Number Example
1386*2=2772, we observe that at tens and hundreds place digits are the same. Hence, 1386 is a strontio number. 1221*2=2442, digits at tens and hundreds place are the same. Hence, 1221 is a strontio number.
Some other strontio numbers are 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 1001, 2002, 3003, etc.
Steps to Find Strontio Number
Let's understand the above steps mathematically.
1221 (from step 1)
1221×2=2442 & nbsp;(from step 2)
2442%1000=442 (from step 3)
442/10=44 (from step 4)
44/10=4 (from step 5)
44%10=4 (from step 5)
4=4 (from step 6)
We observe that tens and hundreds place have the same digits. Hence, the given number 1221 is a strontio number. Similarly, we can check other numbers also.
Let's implement the above steps in a Java program.
Strontio Number Java Program
Enter the number: 1386 1386 is a strontio number.
Enter the number: 7587 7587 is not a strontio number.
Let's create another Java program to check if the given number is strontio or not.
In the following program, we have used the same logic as above. The only difference is that in the following program we have performed each step separately. While in the above program, we have performed three to four steps in a single statement. The above program reduces the lines of code.
Enter the number: 1111 1111 is a strontio number.
Enter the number: 1875 1875 is not a strontio number.