Write a program to check and input an automorphic number
ALGORITHM:
STEP 1: START
STEP 2: Declare a class Automorphic
STEP 3: Type Casting
STEP 4: Print “enter the number:”
STE P 5: Initialize x and sq as integer
STEP 6: Initialize temp=x and c=0
STEP 7: while(temp<0)
STEP 8: temp=temp/10 and c++ //removes the last digit of variable x
STEP 9: Initialize as integer and end=sq%(int)Math.pow(10,c) //determines the last digit of variable sq
STEP 10: if(x==end) //compares x with the last digit of variable sq
STEP 11: Print for Automorphic number
STEP 12: Print if the number is not an Automorphic number
STEP 13: END
SOLUTION:
import java.util.*;
class Automorphic
public static void main(String args[])
Scanner SC=new Scanner(System.in);
System.out.println("Enter the number:");
int x=SC.nextInt();
int sq=(int)Math.pow(x,2);
int temp=x;
int c=0;
while (temp>0)
temp=temp/10;
c++;
int end=sq%(int)Math.pow(10,c);
if (x==end)
System.out.println("Automorphic Number="+x);
else
System.out.println("Not an automorphic Number="+x);
VARIABLE DESCRIPTION TABLE:
S.No. Variable Name Data Type Description
1. x Int To store the input number
2. temp Int To copy and store the value of x into
temp
3. sq Int To store the square of number
4. c int Counter variable
Write a program to check and input for Emirp number
Algorithm
STEP 1: START
STEP 2: Define a class Emirp
STEP 3: Parameterised constructor
STEP 4: if(n<=1) then the loop shall return false
STEP 5: for(int i=2;i<n;i++) and if(n%i==0) //loop executes from 2 to n-1
STEP 6: return false; return true; //returns false if the condition is true otherwise returns false
STEP 7: public static Boolean isEmirp(int n) //function to check if the given number is emirp or not
STEP 8: if(isPrime(n)==false) then return false
STEP 9: Initialise as integer and int reverse=0 //variable to store the reverse of number
STEP 10: while(n!=0) //executes until the specified condition becomes false
STEP 11: int digit=n%10 //finds last digit of number
STEP 12: reverse=reverse*10+digit
STEP 13: n=n/10 //removes last digit
STEP 14: return isPrime(reverse) //user-defined; checks if the reverse number is prime or not
STEP 15: Print a message to input a number
STEP 16: Initialise n as integer
STEP 17: if(isEmirp(n)==true)
STEP 18: Print if the number is an emirp number
STEP 19: Print if the number is not an emirp number
STEP 20: END
SOLUTION
import java.util.*;
public class Emirp
{
public static boolean isPrime(int n)
if(n<=1)
return false;
for(int i=2;i<n;i++)
if(n%i==0)
return false;
return true;
public static boolean isEmirp(int n)
if(isPrime(n)==false)
return false;
int reverse=0;
while(n!=0)
int digit=n%10;
reverse=reverse*10+digit;
n=n/10;
return isPrime(reverse);
public static void main(String args[])
{
Scanner SC=new Scanner(System.in);
System.out.println("Enter a number to check:");
int n=SC.nextInt();
if(isEmirp(n)==true)
System.out.println("Entered number is an emirp number");
else
System.out.println("Entered number is not an emirp number");
VARIABLE DESCRIPTION TABLE
S.No. Variable Name Data Type Description
1. n int To store the value of input number
2. i int For looping statements
3. reverse int To store the value of reversed number
4. digit int To find the last digit of number
Write a program to input and check if a matrix is transpose matrix or not
ALGORITHM
STEP 1: START
STEP 2: Define a class Transpose
STEP 3: Type casting
STEP 4: Print the number of total rows and columns
STEP 5: Initialize row and column as integer
STEP 6: Initialize A[][]=new int[row][column] as integer
STEP 7: Print a message for entering the matrix
STEP 8: for(int i=0;i<row;i++) //loop executes from 0 to the number of rows
STEP 9: for(int j=0;j<column;j++) //loop executes from 0 to the number of columns
STEP 10: A[i][j]=SC.nextInt
STEP 11: Print the original matrix
STEP 12: for(int 1=0;i<row;i++)
SREP 13: for(int j=0;j<column;j++)
STEP 14: Print A[i][j] with a space
STEP 15: Print a message as Transpose Matrix
STEP 16: for(int i=0;i<row;i++)
STEP 17: for(int j=0;j<column;j++)
STEP 18: Print A[i][j] with a space
STEP 19: END
SOLUTION
import java.util.*;
class Transpose
{
public static void main(String args[])
Scanner SC=new Scanner(System.in);
System.out.println("Enter total rows and columns:");
int row=SC.nextInt();
int column=SC.nextInt();
int A[][]=new int[row][column];
System.out.println("Enter matrix:");
for(int i=0;i<row;i++)
for(int j=0;j<column;j++)
A[i][j]=SC.nextInt();
System.out.println("Original Matrix");
for(int i=0;i<row;i++)
for(int j=0;j<column;j++)
System.out.print(A[i][j]+" ");
System.out.println(" ");
}
System.out.println("Transpose Matrix:");
for(int i=0;i<row;i++)
for(int j=0;j<column;j++)
System.out.print(A[j][i]+" ");
System.out.println(" ");
VARIABLE DESCRIPTION TABLE
S.No. Variable Name Data Type Description
1. row int To store the number of input rows
2. column int To store the number of input columns
3. I,j int For looping statements
4. A[][] int For double dimensional array
Write a program to input a matrix and find its boundary elements
ALGORITHM
STEP 1: START
STEP 2: Declare a class Boundary
STEP 3: Type casting
STEP 4: Print the size of input array
STEP 5: Initialize n as integer int n=SC.nextInt()
STEP 6: Initialize A[][] as integer int A[][]=new int[n][n];
STEP 7: for(int i=0;i<n;i++) //loop executes from 0 to the number of rows
STEP 8: for(intj=0;j<n;j++) //loop executes from 0 to the number of columns
STEP 9: A[I][J]=SC.nestInt()
STEP 10: Print the original matrix
STEP 11: for(int i=0;i<n;i++)
STEP 12: : for(intj=0;j<n;j++)
STEP 13: Print A[i][j] with a space
STEP 14: Print a message for boundary elements
STEP 15: for(int i=0;i<n;i++)
STEP 16: for(intj=0;j<n;j++)
STEP 17: if(i==0||j==0||i==n-1||j==n-1) //condition for boundary elements
STEP 18: Print a message A[i][j]+””
STEP 19: else print it with a space
STEP 20: END
SOLUTION
import java.util.*;
class Boundary
{
public static void main(String args[])
Scanner SC=new Scanner(System.in);
System.out.println("Enter the size:");
int n=SC.nextInt();
int A[][]=new int[n][n];
System.out.println("Enter the elements:");
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
A[i][j]=SC.nextInt();
System.out.println("Matrix:");
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
System.out.print(A[i][j]+" ");
System.out.println();
System.out.println("Boundray elemets:");
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(i==0||j==0||i==n-1||j==n-1)
System.out.print(A[i][j]+"");
else
System.out.print(" ");
System.out.println();
VARIABLE DESCRIPTION TABLE
S.No. Variable Name Data Type Description
1. n int To store the value of input number
2. A[][] int To store the array
3. I,j int For looping statements