0% found this document useful (0 votes)
8 views

Algorithm For A Circular Matrix Program

Uploaded by

doggogood9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Algorithm For A Circular Matrix Program

Uploaded by

doggogood9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

reverse(int num) method:

Step 1:-Takes an integer num as input.

Step 2:-Initializes rev to 0.

Step 3:-Uses a while loop to reverse the digits of num by repeatedly extracting the last digit (d) and
adding it to rev after multiplying it by 10.

Step 4:-Continues the loop until num becomes 0.

Step 5:-Returns the reversed number.

isAdam(int num) method:

Step 1:-Takes an integer num as input.

Step 2:-Calculates the square of num (sqNum).

Step 3:-Reverses the digits of num and calculates the square of the reversed number (sqRevNum).

Step 4:-Reverses the square of num (rev).

Step 5:-Checks if rev is equal to sqRevNum. If true, it means the number is a Prime-Adam integer and
returns true; otherwise, returns false.

isPrime(int num) method:

Step 1:-Takes an integer num as input.

Step 2:-Initializes a counter c to 0.

Step 3:-Uses a for loop to iterate from 1 to num, incrementing c for each divisor of num.

Step 4:-Checks if c is equal to 2, indicating that num has exactly two divisors (1 and num). If true, returns
true (indicating a prime number); otherwise, returns false.

main method:

Step 1:-Creates a Scanner object to read user input.


Step 2:-Prompts the user to enter values for m and n.

Step 3:-Checks if m is greater than or equal to n and prints "INVALID INPUT" if true, then exits the
program.

Step 4:-Iterates through the range [m, n] and prints Prime-Adam integers, updating a counter (count) for
each occurrence.

Step 5:-If no Prime-Adam integers are found (count == 0), it prints "NIL."

Step 6:-Prints the frequency of Prime-Adam integers.

You might also like