Professional Documents
Culture Documents
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 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 14: If N is not greater than 3 and if N is not lesser than 10 then print “SIZE OUT OF
RANGE”.
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.
ALGORITHM
Step 1: Declare class CompositeMagicNumber.
Step 3: Declare a scanner object in and take two integer variables m and n to take two input
from the user .
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 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.
ALGORITHM
Step 1: Declare a class First_10_Fermat_Numbers.
Step 6: Inside the loop initialize result with ((2 raised to the power of 2n )+1).
Step 7: Increment n by 1.
ALGORITHM
Step 1: Declare a class FascinatingNumber.
Step 3: Declare three integer variables num, n2, n3 initialize them with a scanner object, num
* 2, num * 3 respectively.
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 11: Check if found is equals to true then print it is a fascinating number otherwise print
it is not a fascinating.
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).
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.
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 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 12: Declare long variables rem, div and initialize them with num%10, num/10
repectively.
Step 15: Check if num%N is not equals to 0 then return false and close the while loop.
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 4: Inside the loop initiate another loop from j=i to 6-1.
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 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 6: Create a function readLimit with return type as void and input the values of the
variables x and n from the user
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 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.
POP OPERATION:
Step 8 - If the stack is not empty, accesses the data element at which top is pointing.
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.