In this section, we will explore the concept of strontio numbers and develop Java programs to determine whether a given number qualifies as a strontio number. Strontio numbers are often encountered in Java coding tests and academic assignments. Our focus will be on understanding the properties of strontio numbers and implementing code to check if a given number meets the criteria for being classified as a strontio number.
What is a Strontio Number?
Strontio numbers are four-digit numbers that, when multiplied by 2, yield the same digit at the hundreds and tens place. It is important to note that the input number must be a four-digit number. In our exploration, we will understand the characteristics of strontio numbers and create Java programs to determine whether a given number qualifies as a strontio number.
Strontio Number Example in Java
We can identify strontio numbers by observing the property that when a four-digit number is multiplied by 2, the resulting product has the same digit at the tens and hundreds place. For example, when we multiply 1386 by 2, we obtain 2772, where the digits at the tens and hundreds places are the same. Therefore, 1386 is a strontio number. Similarly, when we multiply 1221 by 2, we get 2442, and again the digits at the tens and hundreds place are the same, confirming that 1221 is a strontio number.
Other examples of strontio numbers include 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 1001, 2002, 3003, and so on.
Steps to Find Strontio Number
- Read or assign a value to the variable N.
- Multiply the given number N by 2.
- Find the remainder by dividing the resultant from step 2 by 1000. This step removes the first digit from the resultant.
- Divide the resultant from step 2 by 1000. This step gives a two-digit number by removing the last digit from the resultant.
- Divide the two-digit number from step 4 by 10 and find the quotient. Use the modulo operator to find the remainder.
- Compare both the remainder and quotient. If they are equal, the given number N is a strontio number. Otherwise, it is not.
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)
By observing that the tens and hundreds of place digits are the same, we can determine whether a number is a strontio number. For example, the given number 1221 exhibits this property, where the digits at the tens and hundreds places are the same. Thus, 1221 is a strontio number
Strontio Number Java Program
StrontioNumberExample1.java
import java.util.*; public class StrontioNumberExample { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.print("Enter the number: "); //reading an integer from the user int num=sc.nextInt(); int n=num; //first, we have multiplied a number by 2 //the resultant is divided by 1000 that gives the remainder and removes the first digit //at last, the resultant is divided by 10 that removes the last digit //therefore, we get a two-digit number that are mean digits of the given number num=(num*2%1000)/10; //divide the two-digit number (that we get from the above) by 10 and find the remainder //compares the remainder and quotient if(num%10==num/10) //if equal, prints strontio number System.out.println(n+ " is a strontio number."); else //prints if not a strontio number System.out.println(n+ " is not a strontio number."); } }
Output 1:
Enter the number: 1386 1386 is a strontio number.
Output 2:
Enter the number: 1545 1545 is not a strontio number.
Here is an alternative Java program to check whether a given number is a strontio number or not
In the following program, we follow the same logic as mentioned before. However, the steps are performed separately for better clarity and understanding. The program prompts the user to enter a four-digit number, multiplies it by 2, and performs the necessary operations to check if it is a strontio number or not.
StrontioNumberExample2.java
import java.util.*; public class StrontioNumberExample1 { public static void main(String args[]) { Scanner sc=new Scanner (System.in); System.out.print("Enter a four-digit number:"); //reading an integer from the user int num=sc.nextInt(); //checks if the given number is a four-digit number or not if((num>999)&&(num<10000)) { int n=num; //multiplies the given number by 2 num=num*2; //removes first digit num=num/10; //removes last digit num=num%100; //compares the quotient and remainder if((num/10)==(num%10)) System.out.println(n+" is a strontio number."); else System.out.println(n+" is not a strontio number"); } else System.out.println("Please enter a four-digit number."); } }
Output 1:
Enter a four-digit number:1111 1111 is a strontio number.
Output 2:
Enter a four-digit number:8520 8520 is not a strontio number
To delve deeper into subjects like Strontio Number in Java, please visit tutorials.freshersnow.com for additional knowledge.