write a program to check whether a number is strontio number or not.( java)
Answers
Question:-
- write a program in Java to check whether a number is strontio number or not
_______________
•What is Strontio number?
Strontio number is a four digit number when multiplied by 2 gives the same digit in hundred and tens place.
Example:-
1386
1386×2=2772 [ Digits in Hundreds and Tens place are same ]
_______________
Sample Input:-
1386
Sample Output:-
1386 is a Strontio Number
_______________
Code:-
package Coder;
import java.util.*;
public class StrontioNumber {
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
System.out.print("Enter a four-digit number:");
int n=sc.nextInt();
if((n>999)&&(n<10000))
{
int n1=n;
n=n*2; //Multiplying the number by 2
n/=10; //Removing First Digit
n%=100; //Removing Last Digit
if((n/10)==(n%10))
System.out.println(n1+" is a Strontio Number");
else
System.out.println(n1+" is not a Strontio number");
}
else
System.out.println("Number is not a four digit number");
}
}
_________________
•Output Attached
Required Answer:-
Question:
- Write a program to check whether a number is a Strontio number or not.
Code:
Here is the code.
import java.util.*;
public class StrontioNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
int n=sc.nextInt();
n=(n*2%1000)/10;
if(n%10==n/10)
System.out.println("Number is a Strontio Number.");
else
System.out.println("Number is not a Strontio Number.");
sc.close();
}
}
Logic:
- A number is said to be a strontio number which when multiplied by 2 gives same number in tens and hundreds place.
- Example: 1221, 1221 × 2 = 2442, 4 and 4 are same.
Output is attached.