Page 296 - CA_Blue( J )_Class9
P. 296
You will get the following output:
Enter a number : 1634
1634 is Armstrong Number
Enter a number : 1256
1256 is not Armstrong Number
Enter a number : 153
153 is Armstrong Number
Enter a number : 5
5 is Armstrong Number
VARIABLE DESCRIPTION
NAME DATATYPE DESCRIPTION
n int Accept a number
rem int Remainder
sum int Sum of the digit extraction
temp int Temporary Variable
count int Counter Variable
Write a program to input a number and print the Automorphic Number: An automorphic
Program 18
number is a number whose square ends in the same digits as the original number.
Example: 25 is an automorphic number as its square is 625 and 25 is present as the last digits.
1 import java.math.*; //importing “math” package
2 import java.util.*; //importing “util” package
3 class Automorphic //class name
4 {
5 public static void main()
6 {
7 Scanner sc= new Scanner(System.in);
8 int n,sq,rem,temp,count=0; //Declaration of variable
9 System.out.print("Enter a number : ");
10 n=sc.nextInt();
11 temp=n; //Taking in temporary variable
12 while(temp>0) //Counting of digits
13 {
14 count++;
15 temp=temp/10;
16 }
17 sq=n*n; //square of n
18 if(n==sq%(int)Math.pow(10,count)) //checking of Automorphic number
294 Touchpad Computer Applications-IX

