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

Algorithm: Step 1: Declare A Class Squarematrix

The algorithm describes steps to determine if a number is cyclic or not. It takes a number as input, isolates the first and second half of digits, and checks if the halves are equal and if the first half satisfies the cyclic property when the whole number is passed into the function recursively. If both conditions are true, it returns true, otherwise it returns false. The key steps are splitting the number into halves, checking equality of halves, and recursively checking the cyclic property on the first half.

Uploaded by

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

Algorithm: Step 1: Declare A Class Squarematrix

The algorithm describes steps to determine if a number is cyclic or not. It takes a number as input, isolates the first and second half of digits, and checks if the halves are equal and if the first half satisfies the cyclic property when the whole number is passed into the function recursively. If both conditions are true, it returns true, otherwise it returns false. The key steps are splitting the number into halves, checking equality of halves, and recursively checking the cyclic property on the first half.

Uploaded by

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

ALGORITHM

Step 1: Declare a class PotentialOfWord

Step 2: Create a function Potential of integer return type and accept one string argument word.

Step 3: Inside the function Potential declare and initialize a string variable str with
word.toUpperCase(), that stores the upper case version of the argument string word.

Step 4: Declare an integer variable l to store the length of the string variable str and initiate a loop
i from 0 to the number of terms l.

Step 5: Inside the loop store the ASCII values of each character for every string given by the user.
Close the function Potential

Step 6: Create a function main with return type as void and declare a Scanner object to take input
from the user and store length of the string input given by the user in an integer variable len.

Step 7: store the last character in a character variable lastChar and check if there is any ‘.’, ‘?’, ‘!’
in the last character, if not then print “Invalid Input”.

Step 8: Store the substring (from index 0 to len - 1) in a string variable str and declare a
StringTokenizer object with str as parameter.

Step 9: Store the number of words from the string input given by the user in an integer variable
wordcount with the help of StringTokenizer.

Step 10: Declare a string array strArr[] and declare an integer array potArr[].

Step 11: Initiate a loop from i=0 to number of words wordcount and inside the loop store each
word and its ASCII value in the arrays strrr[i], potArr[i] respectively and close the loop.

Step 12: Initiate a loop from i=0 to number of words wordcount and Inside the loop print each
word and its ASCII value and close the loop.

Step 13: Initiate a loop from i=0 to number of words wordcount – 1 and inside the loop initiate
another loop from j=0 to wordcount – i – 1 and inside the loop compare the ASCII values of each
word and arrange the words (according to their ASCII values) in ascending order and close the
two loops.

STEP 14: Initiate a loop from i=0 to number of words wordcount and inside the loop print the
arranged words and close the loop.

Step 15: Close the function main and the class PotentialOfWord.

ALGORITHM
Step 1: Declare a class SquareMatrix.
Step 2: Create a function main with return type as void.

Step 3: Declare a bufferedReader object br and link it with an InputStreamReader class and
Store the integer value input in an integer variable N with the help of the bufferedreader
object br.readLine().

Step 4: Check if N>3 and N<10 then declare and initialize a 2D character array M of order
[N][N].

Step 5: Store the 3 characters given by user in three character variables respectively.

Step 6: Initiate a loop from i=0 to N and Inside the loop initiate a loop from j=0 to N.

Step 7: check if i=0 or i=N-1 and j=0 or j=N-1 (Both conditions should be true) to fill the
corners with the first character

Step 8: check if i=0 or j=0 and i=N-1 or j=N-1 (Both conditions should be true) to fill non
corner boundary elements with the second character.

Step 9: When the above conditions are false then fill the rest of the elements with the third
character.

Step 10: Close two loops and print a blank line.

Step 11: Initiate a loop from i=0 to N and Inside the loop initiate a loop from j=0 to N.

Step 12: Print the array M[i][j] and close the loop.

Step 13: Print a line and close the loop.

Step 14: If N is not greater than 3 and if N is not lesser than 10 then print “SIZE OUT OF
RANGE”.

Step 15: Close the function main.

Step 16: Close the class SquareMatrix.

ALGORITHM
Step 1: Declare a class Repeat

Step 2: Initialize a global integer array st[] with data limit = 100, initialize cap, f, r as global
integer variables.
Step 3: Create parametrized constructor Repeat() with int m as its parameter, to initialize the
global variables to 0.

Step 4: Declare a function pushvalue with (int v) as parameter and return type as void to add
integers from the rear index and Inside the function, if (r+1)<=cap, then assign r+1 to r, v to
array str[r].

Step 5: Check if (r+1)<=cap I false, then print “OVERFLOW” and close the function
pushvalue().

Step 6: Declare a function popvalue with return type as Integer and inside the function
declare an integer variable v.

Step 7: Check if (r!=f), then assign f+1 to f, st[f] to v otherwise return -9999 and close the
function popvalue().

Step 8: Declare a function display() with return type as void and inside the function check
if(r!=f), then initiate a loop from i=f+1 to r.

Step 9: Inside the loop print the array st[i] and close the loop.

Step 10: if (r!=f) is false, then print “Queue is empty” and close the function display().

Step 11: Declare a function main with return type as void to invoke the above functions.

Step 12: Declare a scanner object sc to take input from the user.

Step 13: Create an object r of the class Repeat to call the functions.

Step 14: Call the function pushvalue(), popvalue, display.

Step 15: Close the function main.

Step 16: Close the class Repeat.

ALGORITHM
Step 1: Declare class CompositeMagicNumber.

Step2: Declare a function main with return type as void.

Step 3: Declare a scanner object in and take two integer variables m and n to take two input
from the user .

Step 5: Check if m<1 or n<1 or m>n, then print “Invalid Input”.


Step 6: Take an integer variable count and initialize it with 0.

Step 7: Initiate a loop from i = m to n and inside the loop take a Boolean variable
isComposite and initialize it with false.

Step 8: Initiate another loop from j=2 to I and Inside the loop check if i is divisible by j, then
change the value of isComposite to true. Then close the loop

Step 9: Then check if isComposite is equals to true and i is not equal to 1, then declare an
integer variable num and initialize it with i.

Step 10: Initiate a while loop till num > 9, then declare an integer variable sum and initialize
it with 0 and inside the loop initiate another while loop till num not equals to 0.

Step 11: Inside the loop declare an integer variable d to store the integer value of the
remainder of num/10.

Step 12: Then increment num by num/10.

Step 13: Then increment sum by d and close the 2nd while loop.

Step 14: Assign sum to num and close the 1st while loop.

Step 15: Check if num is equals to 1, then increment the count by 1 and print i and close the
1st for loop.

Step 16: Print “Frequency of composite magic numbers:” with the value of count.

Step 17: Close the function main.

Step 18: Close the class CompositeMagicNumber.

ALGORITHM
Step 1: Declare a class First_10_Fermat_Numbers.

Step2: Declare a function main with return type as void.

Step 3: Declare an integer variable n and initialize it with0.

Step 4: Declare a double variable result.

Step 5: Initiate a while loop till n=10.

Step 6: Inside the loop initialize result with ((2 raised to the power of 2n )+1).

Step 7: Increment n by 1.

Step 8: Print result.


Step 9: Close the while loop.

Step 10: Close the function main.

Step 11: Close the class First_10_Fermat_Numbers.

ALGORITHM
Step 1: Declare a class FascinatingNumber.

Step2: Declare a function main with return type as void.

Step 3: Declare three integer variables num, n2, n3 initialize them with a scanner object, num
* 2, num * 3 respectively.

Step 4: Declare a string variable concatstr and initialize it with num+””+n2+n3.

Step 5: Declare a boolean variable found and initialize it with true value.

Step 6: Initialize a for loop from c= ‘1’ to ‘9’ and inside the loop declare an integer variable
count and initialize it with 0.
Step 7: Initialize another loop from i=0 to the length of the string concatstr and inside the
loop declare and initialize a character variable ch with concatstr.charAt(i) to store each
character for every index i.

Step 8: check if ch is equals to c and increment the count by 1 and close the loop.

Step 9: Check if count > 1 or count is equals to 0 then assign false value to found and break.

Step 10: Close the 1st for loop.

Step 11: Check if found is equals to true then print it is a fascinating number otherwise print
it is not a fascinating.

Step 12: Close the function main.

Step 13: Close the class FascinatingNumber.

ALGORITHM
Step 1: Declare a class Narcissistic_number.

Step 2: Declare a function is_narc_dec_num() with return type as Boolean and its parameter
is (long n).

Step3: Inside the function check if n < 0 then return false.

Step4: Declare a string variable str1, an integer variable x, a long variable and initialize them
with Long.toString(n), str1.length, 0 respectively.

Step 5: Initialize a loop like this [for(char c : str1.toCharArray())], inside the loop increment
sum_num by Math.pow(Character.digit(c, 10), x).

Step 6: Return the boolean value of sum_num==n and close the function.

Step 7: Declare a function main with return type as void and inside the function initiate a loop
from n=0, ctr = 0 to 15.
Step 8: Inside the loop Check if the value of is_narc_dec_num(n) is true then print n and
increment the ctr by 1. Close the loop.

Step 9:Close the function main and the class Narcissistic_number.

ALGORITHM
Step 1: Declare a class Cyclic_Number.

Step 2: Declare a function isCyclic() with return type boolean and its parameter is long N.

Step 3: Declare a long variable num, an integer variable count, an integer variable digit, a
boolean variable allSame and initialize them with N, 0, (int)(num%10), true respectively.

Step 4: Initialize a while loop till num > 0 and inside the loop increment count by 1.

Step 5: Check if (num%10) is not equals to digit, then assign false value to allSame and
increment num by num/10.

Step 6: Close the while loop.

Step 7: Check if allSame is equals to true, then return false.

Step 8: Check if (Count % 2) is equals to 0 then declare long variables halfPower, firsthalf,
secondhalf and initialize them with (long)Mah.pow(10, count/2), N%halfPower,
N/halfpower.
Step 9: Check if firstHalf is equals to firsthalf and isCyclic(firstHalf) is equals to true, then
return false.

Step 10: declare N to num.

Step 11: Initiate a while loop till it returns true.

Step 12: Declare long variables rem, div and initialize them with num%10, num/10
repectively.

Step 13: Assign (long)(Math.pow(10, count-1))*rem+div to num.

Step 14: Check if num is equals to N then break.

Step 15: Check if num%N is not equals to 0 then return false and close the while loop.

Step 16: Return true and close the function.

Step 17: Declare a function main with return type as void.

Step 18: Declare a Scanner object sc and declare a long variable N to take the input.

Step 19: Check if (isCyclic(N)) is true then print yes otherwise print no.

Step 20: Close the function main and the class Cyclic_Number.

ALGORITHM
Step 1: Declare a class Pattern.

Step 2: Declare a function main with return type as void.

Step 3: Inside the function initiate a loop from i=1 to 6.

Step 4: Inside the loop initiate another loop from j=i to 6-1.

Step 5: Inside the loop print “ ” and close the loop.

Step 6: Initiate a loop from j=1 to I and inside the loop print j and close the loop.

Step 7: Inside the loop from j=i-1 to 1 and inside the loop print j and close the loop.

Step 8: Print a line and close the loop.

Step 9: Close the function main.

Step 10: Close the class Pattern.


ALGORITHM
STEP 1: Initialize variables x, n and sum as global variables

STEP 2: Create a non-parameterized constructor and set the values of the variables to their
default values

STEP 3: Create a function getPower of integer return type and accept two integer arguments
m and p

STEP 4: Inside the function check if p=0,if yes, return 1. This is the base case.

STEP 5: If the value of p is not equal to 0, return m*getPower(m and p-1)

STEP 6: Create a function readLimit with return type as void and input the values of the
variables x and n from the user

STEP 7: Create a function Sum with return type as void

STEP 8: Inside this function, initiate a loop i from 1 to the number of terms n

STEP 9: Pass two variables through getPower; one with i and i values and the other with x
and i*2 as arguments

STEP 10: Store the value of the second variable divided by the first variable in a variable sum
and keep adding the values
STEP 11: Print the sum outside the loop

STEP 12: Create a function main with return type as void to call all the functions

ALGORITHM
The given program involve STACK Algorithm.

PUSH OPERATION:

Step 1 - Checks if the stack is full.

Step 2 - If the stack is full, produces an error and exit.

Step 3 - If the stack is not full, increments top to point next empty space.

Step 4 - Adds data element to the stack location, where top is pointing.

Step 5 - Returns success.

POP OPERATION:

Step 6 - Checks if the stack is empty.

Step 7 - If the stack is empty, produces an error and exit.

Step 8 - If the stack is not empty, accesses the data element at which top is pointing.

Step 9 - Decreases the value of top by 1.

Step 10 - Returns success.


ALGORITHMS
Step 1: Declare a class Moblie_Repairing.

Step 2: Declare t[], bb, ss, mm, ct, a, j, k, i as integer variables and B[], S[], M[], Q[] a string
variables.

Step 3: Declare a constructor Mobile_Repairing() and inside the constructor initialize all the
variables declared above and close the constructor.

Step 4: Declare a function m() with return type as void and inside the function declare an
object ob of class Project, declare a character variable ans.

Step 5: Initiate do while loop till ans is not equal to n and inside the loop initialize the
variable t[i] with sc.nextInt(),declare and initialize a variable ch with sc.next().charAt(0).

Step 6: Use a switch case with ch as input and inside the switch case give three cases ‘B’, ‘S’,
‘M’.

Step 7: Inside the switch case, for case ‘B’ increment bb by 1 and assign ct + “B” to B[a++]
assign B[a-1] to Q[i] and break, for case ‘S’ increment ss by 1 and assign ct + “S” to S[j++]
assign S[j-1] to Q[i] and break, for case ‘M’ increment mm by 1 and assign ct + “M” to M[k+
+], assign M[k-1] to Q[i] and break. Close the switch case.

Step 8: Increment i by 1 and then initialize ans with sc.next().charAt(0) to take y or n and
close the loop and close the function m().

Step 9: Declare a function dsp() with return type a void and inside the function declare and
initialize integer variables c=0, i1=0, i2=0, i3=0.

Step 10: Initiate a do while loop till c<ct and inside the loop initiate three for loops from h=0
to h<ct for i1, i2, i3.
Step 11: Inside the three loops same conditions are followed for each ‘B’, ‘S’, ‘M’, and close
the while loop.

Step 12: Declare a main function with return type as void and inside the function call the
functions m(), dsp() by creating new object ob of class Mobile_Repairing.

Step 13: Close the main function.

Step 14: Close the class Mobile_Repairing.

You might also like