Computer Applications
Write a program to input a number and check whether the number is an automorphic number or not.
An automorphic number is a number whose square "ends" in the same digits as the number itself.
e.g. 52 = 25, 62 = 36, 762 = 5776
Answer
import java.util.Scanner;
public class KboatAutomorphic
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int num = in.nextInt();
int numCopy = num;
int sq = num * num;
int d = 0;
/*
* Count the number of
* digits in num
*/
while(num > 0) {
d++;
num /= 10;
}
/*
* Extract the last d digits
* from square of num
*/
int ld = (int)(sq % Math.pow(10, d));
if (ld == numCopy)
System.out.println(numCopy + " is automorphic");
else
System.out.println(numCopy + " is not automorphic");
}
}Output
Related Questions
Write a program to print following patterns.
(i)
1 2 3 4 5 1 2 3 4 1 2 3 1 2 1(ii)
A B A C B A D C B A E D C B AWrite a program to input and store integer elements in a double dimensional array of size 4 x 4 and find the sum of all the elements.
7 3 4 5 5 4 6 1 6 9 4 2 3 2 7 5Sum of all the elements: 73
Design a class RailwayTicket with following description:
Class name : RailwayTicket
Data Members Purpose String name To store the name of the customer String coach To store the type of coach customer wants to travel long mob no To store customer's mobile number int amt To store basic amount of ticket int totalamt To store the amount to be paid after updating the original amount Member Methods Purpose void accept() To take input for name, coach, mobile number and amount void update() To update the amount as per the coach selected (extra amount to be added in the amount as per the table below) void display() To display all details of a customer such as name, coach, total amount and mobile number Type of Coaches Amount First_AC ₹700 Second_AC ₹500 Third_AC ₹250 Sleeper None Write a main method to create an object of the class and call the above member methods.
Write a program to accept a string. Convert the string into upper case letters. Count and output the number of double letter sequences that exist in the string.
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE"
Sample Output: 4