In the previous article, we have discussed Java Program to Check Smith Number
In this article we are going to understand what Strontio number is and how we can check whether a number is Strontio or not in Java with examples.
Program to Check Strontio Number
Strontio numbers are numbers which when multiplied with 2, the ten’s and hundred’s digits are the same.
Example : 1386: 1386*2=2772 Strontio number 1221: 1221*2=2442 Strontio number 1250: 1250*2=2500 Not a Strontio number
In the above examples the number 1386 and 1221 are Strontio numbers as the digits at its ten’s and hundred’s place when multiplied with 2 are equal. However 1250 is not a Strontio number as both the digits are different.
Let’s see different ways to check Strontio number.
Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.
Approach :
- Enter/Declare a number and store it .
- Then we multiply it by 2 and find remainder when divided by 10 and 1000.
- If both the remainders are equal, then the number is said to be a Strontio number.
Method-1: Java Program to Check Strontio Number By Using Static Value
import java.util.Scanner; public class StrontioNumber { public static void main(String args[]) { //A number declared int num = 1555; int prod = num*2, rem1, rem2; //Gives last 3 digits prod = prod%1000; //Now Removes the last digit prod /=10; //Now only 2 digits in the number. // Rem1 holds the 10's digit while rem2 holds the 100's digit rem1 = prod%10; rem2 = prod/10; if(rem1==rem2) { System.out.println(num+" is a Strontio number"); } else { System.out.println(num+" is Not a Strontio number"); } } }
Output: 1555 is a Strontio number
Method-2: Java Program to Check Strontio Number By User Input Value
import java.util.Scanner; public class StrontioNumber { public static void main(String args[]) { //Taking the number as input from the user using scanner class Scanner scan = new Scanner(System.in); System.out.print("Enter a number : "); int num = scan.nextInt(); int prod = num*2, rem1, rem2; //Gives last 3 digits prod = prod%1000; //Now Removes the last digit prod /=10; //Now only 2 digits in the number. // Rem1 holds the 10's digit while rem2 holds the 100's digit rem1 = prod%10; rem2 = prod/10; if(rem1==rem2) { System.out.println(num+" is a Strontio number"); } else { System.out.println(num+" is Not a Strontio number"); } } }
Output: Case-1 Enter a number : 1386 1386 is a Strontio number Case-2 Enter a number : 1551 1551 is a Strontio number
Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.
Related Java Programs: