0% found this document useful (0 votes)
69 views57 pages

Computer Science Project Term 1 (Xii)

Uploaded by

jbezos9000
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)
69 views57 pages

Computer Science Project Term 1 (Xii)

Uploaded by

jbezos9000
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/ 57

PROGRAM 1

Page 1 of 57
QUESTION
The coordinates of a point P on a two dimensional plane can be represented by P(x,y) with x as
the x-coordinate and y as the y-coordinate.The coordinates of midpoint of two points P1(x1,yI)
and P2(x2,y2) can be calculated as P(x,y) where:

x=(xl+x2)/2,y=(y1+y2)/2

Design a class Point with the following details:

Classname : Point

DataMembers / instancevariables:

x: stores the x-coordinate


y : stores the y-coordinate

Member functions:

Point(): constructor to initialize x=0,y=0 void


readpoint(): accepts the coordinates x and y of a point
Point midpoint(Point A,Point B): calculates and returns the midpoint of the two points A and B
void displaypoint():displays the coordinates of a point

Specify the class Point giving details of the constructor() , member functions void readpoint()
Point midpoint(Point,Point) and void displaypoint() along with the main() function to create an
object and call the functions accordingly to calculate the midpoint between any two given points.

Page 2 of 57
ALGORITHM
Step 1: Start.

Step 2: Declare a class named ‘Point’.

Step 3: Declare variables x and y of double data type.

Step 4: Initialize the variables in the Point() constructor.

Step 5: In the readpoint() method, take the values of x and y as input from the user.

Step 6: In the displaypoint() method, print the values of x and y.

Step 7: In the midpoint() method, calculate and return the mid-point of the two points A and B.

Step 8: In the main() method, create necessary objects and print the required co-ordinates.

Step 9: Stop.

Page 3 of 57
SOURCE CODE
import java.util.Scanner;

public class Point

double x,y;

Scanner sc = new Scanner(System.in);

public Point()

x=0.0;

y=0.0;

public void readpoint()

System.out.println("enter x");

x=sc.nextDouble();

System.out.println("enter y");

y=sc.nextDouble();

public void displaypoint()

System.out.println(x);

System.out.println(y);

public Point midpoint(Point A,Point B)

Page 4 of 57
{

Point C=new Point();

C.x=(A.x+B.x)/2;

C.y =(A.y+B.y)/2;

return C;

public static void main()

Point p=new Point();

Point q=new Point();

Point r=new Point();

p.readpoint();

q.readpoint();

r=r.midpoint(p,q);

p.displaypoint();

q.displaypoint();

r.displaypoint();

Page 5 of 57
VARIABLE DESCRIPTION
TABLE
Variable Data Type Purpose
x int Value of x-ordinate taken as
input from the user.
y int Value of y-ordinate taken as
input from the user.

Page 6 of 57
OUTPUTS

Page 7 of 57
PROGRAM 2

Page 8 of 57
QUESTION
A unique-digit integer is a positive integer (without leading zeros) with no duplicates digits. For
example 7, 135, 214 are all unique-digit integers whereas 33, 3121, 300 are not. Given two
positive integers m and n, where m < n, write a program to determine how many unique-digit
integers are there in the range between m and n (both inclusive) and output them. The input
contains two positive integers m and n. Assume m < 30000 and n < 30000. You are to output the
number of unique-digit integers in the specified range along with their values in the format
specified below:

Sample Input:
m = 100
n = 120
Sample Output: The Unique-Digit integers are: 102, 103, 104, 105, 106, 107, 108, 109, 120.
Frequency of unique-digit integers is: 9

Sample Input:
m = 2500
n = 2550
Sample Output: The Unique-Digit integers are: 2501, 2503, 2504, 2506, 2507, 2508, 2509, 2510,
2513, 2514, 2516, 2517, 2518, 2517, 2530, 2519, 2530, 2531, 2534, 2536, 2537, 2538, 2539,
2540, 2541, 2543, 2546, 2547, 2548, 2549.
Frequency of unique-digit integers is: 28.

Page 9 of 57
ALGORITHM
Step 1: Start.

Step 2: Take m and n as user-input.

Step 3: If m (or n) < 1, m (or n) > 30000 or m > n, print an error message and terminate the
program accordingly.

Step 4: Declare a variable of int data type to count the number of unique numbers. (count)

Step 5: Start a for loop.

Step 6: Declare an array of boolean data type (visited[]), a variable (isUnique) to check if a
number is unique and create a copy variable of the looping variable (num).

Step 7: Inside a while loop, initialize a variable d=num%10.

Step 8: If visited[d] returns true, then the number is not unique.

Step 9: Divide the number by 10 inside the while loop for every iteration.

Step 10: If isUnique returns true i.e. the number is unique, then add 1 to count and print the
unique number.

Step 11: Outside the loops, print the frequency of unique-digit integers in the next line.

Step 12: Stop.

Page 10 of 57
SOURCE CODE
import java.util.Scanner;

public class UniqueIntegers

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.print("Enter m: ");

int m = in.nextInt();

if (m < 1 || m > 30000)

System.out.println("Value of m should be between 1 and 30000");

return;

System.out.print("Enter n: ");

int n = in.nextInt();

if (n < 1 || n > 30000)

System.out.println("Value of n should be between 1 and 30000");

return;

if (m > n)

System.out.println("Value of m should be less than n");

Page 11 of 57
return;

System.out.println("The Unique-Digit integers are:");

int count = 0;

for (int i = m; i <= n; i++)

int num = i;

boolean visited[] = new boolean[10];

boolean isUnique = true;

while (num != 0)

int d = num % 10;

if (visited[d])

isUnique = false;

break;

visited[d] = true;

num /= 10;

if (isUnique)

count++;

System.out.print(i + " ");

Page 12 of 57
}

System.out.println();

System.out.println("Frequency of unique-digit integers is: " + count);

VARIABLE DESCRIPTION
TABLE
Variable Data Type Purpose
m int User input
n int User input
i int Looping variable
num int Copy variable
count int Counts the number of unique-
digit numbers
d int Stores modulus of num
visited[] boolean Array to check if a number is
unique-digit or not
isUnique boolean Returns true if the number is
unique-digit

Page 13 of 57
OUTPUTS

Page 14 of 57
PROGRAM 3

Page 15 of 57
QUESTION
An Evil number is a positive whole number which has even number of 1's in its binary
equivalent. Example: Binary equivalent of 9 is 1001, which contains even number of 1's. A few
evil numbers are 3, 5, 6, 9…. Design a program to accept a positive whole number and find the
binary equivalent of the number and count the number of 1's in it and display whether it is a Evil
number or not with an appropriate message. Output the result in format given below:

Example 1
Input: 15
Binary Equivalent: 1111
No. of 1's: 4
Output: Evil Number

Example 2
Input: 26
Binary Equivalent: 11010
No. of 1's: 3
Output: Not an Evil Number

Page 16 of 57
ALGORITHM
Step 1: Start.

Step 2: Take an integer as input from the user.

Step 3: If the integer is negative, display an error message and terminate the program.

Step 4: Declare variables of int data type to count the number of 1’s (count), store the exponent
of cardinal number 10 (p) and store the binary equivalent of the input (binNum).

Step 5: Inside a while loop, provided that the input is positive, calculate the binary equivalent of
the integer using the declared variables.

Step 6: Print the binary equivalent and the number of 1’s in it.

Step 7: If the number of 1’s is even (count%2==0), print “Evil Number”, otherwise print “Not an
Evil Number”.

Step 8: Stop.

Page 17 of 57
SOURCE CODE
import java.util.Scanner;

public class EvilNumber

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.print("Enter a positive number: ");

int n = in.nextInt();

if (n < 0)

System.out.println("Invalid Input");

return;

int count = 0;

int p = 0;

int binNum = 0;

while (n > 0)

int d = n % 2;

if (d == 1)

count++;

binNum += (int)(d * Math.pow(10, p));

p++;

Page 18 of 57
n /= 2;

System.out.println("Binary Equivalent: " + binNum);

System.out.println("No. of 1's: " + count);

if (count % 2 == 0)

System.out.println("Output: Evil Number");

else

System.out.println("Output: Not an Evil Number");

VARIABLE DESCRIPTION
TABLE
Variable Data Type Purpose
n int User input
count int Counts the number of 1’s in
the input’s binary equivalent
p int Stores the exponent of
cardinal number 10
binNum int Stores the binary equivalent
d int Stores remainder when input
is divided by 2

Page 19 of 57
OUTPUTS

Page 20 of 57
PROGRAM 4

Page 21 of 57
QUESTION
The result of a quiz competition is to be prepared as follows: The quiz has five questions with
four multiple choices (A, B, C, D), with each question carrying 1 mark for the correct answer.
Design a program to accept the number of participants N such that N must be greater than 3 and
less than 11. Create a double-dimensional array of size (Nx5) to store the answers of each
participant row-wise. Calculate the marks for each participant by matching the correct answer
stored in a single-dimensional array of size 5. Display the scores for each participant and also the
participant(s) having the highest score. Example: If the value of N = 4, then the array would be:

Q1 Q2 Q3 Q4 Q5
Participant 1 A B B C A
Participant 2 D A D C B
Participant 3 A A B A C
Participant 4 D C C A B
Key to the D C C B A
question:

Note: Array entries are line fed (i.e. one entry per line)

Test your program for the following data and some random data.

Example 1

INPUT:
N=5
Participant 1 D A B C C
Participant 2 A A D C B
Participant 3 B A C D B
Participant 4 D A D C B
Participant 5 B C A D D
Key: B C D A A

OUTPUT:
Scores:
Participant 1 = 0
Participant 2 = 1
Participant 3 = 1
Participant 4 = 1
Participant 5 = 2

Page 22 of 57
Highest Score:
Participant 5

Example 2

INPUT:
N=4
Participant 1 A C C B D
Participant 2 B C A A C
Participant 3 B C B A A
Participant 4 C C D D B
Key: A C D B B

OUTPUT:
Scores:
Participant 1 = 3
Participant 2 = 1
Participant 3 = 1
Participant 4 = 3
Highest Score:
Participant 1
Participant 4

Example 3

INPUT:
N = 12

OUTPUT:
INPUT SIZE OUT OF RANGE.

Page 23 of 57
ALGORITHM
Step 1: Start.

Step 2: Take the number of participants as user input.

Step 3: If n <= 3 or n >= 11, print an error message and terminate the program accordingly.

Step 4: Declare arrays for storing answers and key.

Step 5: Using a nested for loop, take the answers of the participants as user input.

Step 6: Using another for loop, take the answer key as user input.

Step 7: Declare a variable of int type to store highest score achieved by a participant (hScore).

Step 8: Declare an array to store and print the scores of each participant (score[]).

Step 9: Using a nested for loop, find the highest score and print the scores.

Step 10: Using a for loop, print the number of the participant with the highest score.

Step 11: Stop.

Page 24 of 57
SOURCE CODE
import java.util.Scanner;

public class QuizCompetition

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.print("Enter the Number of Participants (N): ");

int n = in.nextInt();

if (n <= 3 || n >= 11)

System.out.println("INPUT SIZE OUT OF RANGE.");

return;

char answers[][] = new char[n][5];

char key[] = new char[5];

System.out.println("Enter answers of participants");

for (int i = 0; i < n; i++)

System.out.println("Participant " + (i+1));

for (int j = 0; j < 5; j++)

answers[i][j] = in.next().charAt(0);

Page 25 of 57
}

System.out.println("Enter Answer Key:");

for (int i = 0; i < 5; i++)

key[i] = in.next().charAt(0);

int hScore = 0;

int score[] = new int[n];

System.out.println("Scores:");

for (int i = 0; i < n; i++)

for (int j = 0; j < 5; j++)

if (answers[i][j] == key[j])

score[i]++;

if (score[i] > hScore)

hScore = score[i];

System.out.println("Participant " + (i+1) + " = " + score[i]);

System.out.println("Highest Score:");

Page 26 of 57
for (int i = 0; i < n; i++)

if (score[i] == hScore)

System.out.println("Participant " + (i+1));

VARIABLE DESCRIPTION
TABLE
Variable Data Type Purpose
n int Number of participants taken
as user input
i int Looping variable in for loop
j int Looping variable in for loop
hScore int Stores highest score
score[] int Stores score of the participants
answers[][] char Answers of participants taken
as user input
key[] char Answer key taken as user
input

Page 27 of 57
OUTPUTS

Page 28 of 57
Page 29 of 57
PROGRAM 5

Page 30 of 57
QUESTION
Caesar Cipher is an encryption technique which is implemented as ROT13 ('rotate by 13 places').
It is a simple letter substitution cipher that replaces a letter with the letter 13 places after it in the
alphabets, with the other characters remaining unchanged.

ROT13

A/a B/b C/c D/d E/e F/f G/g H/h I/i J/j K/k L/l M/m
↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕
N/m O/o P/p Q/q R/r S/s T/t U/u V/v W/w X/x Y/y Z/z

Write a program to accept a plain text of length L, where L must be greater than 3 and less than
100.

Encrypt the text if valid as per the Caesar Cipher.

Test your program with the sample data and some random data.

Example 1

INPUT:
Hello! How are you?

OUTPUT:
The cipher text is: Uryyb! Ubj ner lbh?

Example 2

INPUT:
Encryption helps to secure data.

OUTPUT:
The cipher text is:
Rapelcgvba urycf gb frpher qngn.

Example 3

INPUT:
You

OUTPUT:
INVALID LENGTH

Page 31 of 57
ALGORITHM
Step 1: Start.

Step 2: Take a String as user input.

Step 3: If the length of the string is <=3 or >=100, display an error message and terminate the
program accordingly.

Step 4: Create an object of StringBuffer class.

Step 5: Inside a for loop, extract the characters of the String.

Step 6: Substitute the characters with their corresponding characters as provided in the question.

Step 7: Using the substituted characters, construct the encoded String.

Step 8: Print the encoded String.

Step 9: Stop.

Page 32 of 57
SOURCE CODE
import java.util.Scanner;

public class CaesarCipher

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.println("Enter plain text:");

String str = in.nextLine();

int len = str.length();

if (len <= 3 || len >= 100)

System.out.println("INVALID LENGTH");

return;

StringBuffer sb = new StringBuffer();

for (int i = 0; i < len; i++)

char ch = str.charAt(i);

if ((ch >= 'A' && ch <= 'M') || (ch >= 'a' && ch <= 'm'))

sb.append((char)(ch + 13));

else if ((ch >= 'N' && ch <= 'Z') || (ch >= 'n' && ch <= 'z'))

Page 33 of 57
{

sb.append((char)(ch - 13));

else

sb.append(ch);

String cipher = sb.toString();

System.out.println("The cipher text is:");

System.out.println(cipher);

VARIABLE DESCRIPTION
TABLE
Variable Data Type Purpose
len int Stores length of the input
String
i int Looping variable in for loop
ch char Stores each character of the
input String
str String String taken as user input
cipher String Stores the encoded String

Page 34 of 57
OUTPUTS

Page 35 of 57
PROGRAM 6

Page 36 of 57
QUESTION
Write a program which first inputs two integers, the first between 1 to 12 (inclusive) and the
second between 0 to 59 to print the time in words.

Input:

Time = 3, 0
Output = 3 o’ clock

Input:

Time = 3, 1
Output = one minute past 3

Input:

Time = 3, 15
Output = quarter past 3

Input:

Time = 7, 29
Output = 29 minutes past 7

Input:

Time = 8, 30
Output = half past 8

Input:

Time=6, 34
Output = 26 minutes to 7

Input:

Time = 12, 45
Output = quarter to 1

Input:

Time = 12, 59
Output = one minute to 1

Page 37 of 57
Input:

Time = 14, 16
Output = Invalid Input!

ALGORITHM
Step 1: Start.

Step 2: Take the hours and minutes as input from the user.

Step 3: If the hours are not between 1 and 12 (inclusive) or the minutes are not between 0 and 59
(inclusive), print an error message and terminate the program accordingly.

Step 4: Declare a String array would store the numbers in words (zero to twenty-nine).

Step 5: Using the String array, print the time in words using different print statements for
different values or range of values of minutes taken as input.

Step 6: Stop.

SOURCE CODE
// Java program to convert time into words

import java.util.*;

public class Time

// Print Time in words.

static void printWords(int h, int m)

String nums[] = { "zero", "one", "two", "three", "four",

"five", "six", "seven", "eight", "nine",

"ten", "eleven", "twelve", "thirteen",

"fourteen", "fifteen", "sixteen", "seventeen",


Page 38 of 57
"eighteen", "nineteen", "twenty", "twenty one",

"twenty two", "twenty three", "twenty four",

"twenty five", "twenty six", "twenty seven",

"twenty eight", "twenty nine"};

if (m == 0)

System.out.println(nums[h] + " o' clock ");

else if (m == 1)

System.out.println("one minute past " +

nums[h]);

else if (m == 59)

System.out.println("one minute to " +

nums[(h % 12) + 1]);

else if (m == 15)

System.out.println("quarter past " + nums[h]);

else if (m == 30)

System.out.println("half past " + nums[h]);

else if (m == 45)

System.out.println("quarter to " +

nums[(h % 12) + 1]);

else if (m <= 30)

System.out.println( nums[m] + " minutes past " +

nums[h]);

else if (m > 30)

System.out.println( nums[60 - m] + " minutes to " +

nums[(h % 12) + 1]);

Page 39 of 57
}

// Driven code

public static void main(String []args)

Scanner in=new Scanner(System.in);

System.out.println("Enter the time: ");

int h = in.nextInt();

int m = in.nextInt();

if(h<1||h>12||m<0||m>59)

System.out.println("Invalid Input!");

return;

printWords(h, m);

VARIABLE DESCRIPTION
TABLE
Variable Data Type Purpose
h int Stores hour(s) taken as input
m int Stores minute(s) taken as input
nums[] String Stores numbers in words

Page 40 of 57
OUTPUTS

Page 41 of 57
Page 42 of 57
PROGRAM 7

Page 43 of 57
QUESTION
An Emirp number is a number which is prime backwards and forwards. Example: 13 and 31 are
both prime numbers. Thus, 13 is an Emirp number. Design a class Emirp to check if a given
number is Emirp number or not. Some of the members of the class are given below:

Class name: Emirp

Data members/instance variables:

n: stores the number


rev: stores the reverse of the number
f: stores the divisor

Member functions:

Emirp(int nn): to assign n = nn, rev = 0 and f = 2


int isprime(int x): check if the number is prime using the recursive technique and return 1 if
prime otherwise return 0
void isEmirp(): reverse the given number and check if both the original number and the reverse
number are prime, by invoking the function isprime(int) and display the result with an
appropriate message

Specify the class Emirp giving details of the constructor(int), int isprime (int) and void isEmirp().
Define the main function to create an object and call the methods to check for Emirp number.

Page 44 of 57
ALGORITHM
Step 1: Start.

Step 2: Declare the class Emirp.

Step 3: Declare n, rev and f of int data type.

Step 4: Initialize the variable in Emirp()

Step 5: In isprime(int x), using recursion, return 1 if the number is prime otherwise return 0.

Step 6: In isEmirp(), check if the number is Emirp number or not.

Step 7: If the number is an Emirp number, print “Emirp Number” otherwise print “Not an Emirp
Number”.

Step 8: In main() method, take a number as input from the user and invoke the above methods.

Step 9: Stop.

Page 45 of 57
SOURCE CODE
import java.util.Scanner;

public class Emirp

int n,rev,f;

Emirp(int nn)

n=nn;

rev=0;

f=2;

int isprime(int x)

if(n==x)

return 1;

else if(n % x==0 || n==1)

return 0;

else

return isprime(x+1);

Page 46 of 57
}

void isEmirp()

int x=n;

while(x!=0)

rev=(rev*10)+x%10;

x=x/10;

int ansl=isprime(f);

x=n;

n=rev;

f=2;

int ans2=isprime(f);

if(ansl==1 && ans2==1)

System.out.println(x+" is an Emirp number");

else

System.out.println(x+" is not an Emirp number");

public static void main()

Page 47 of 57
{

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number");

int x=sc.nextInt();

Emirp obj1=new Emirp(x);

obj1.isEmirp();

VARIABLE DESCRIPTION
TABLE
Variable Data Type Purpose
N int Static variable; stores user
input
Rev int Stores reverse of the input
F int Stores the divisor which
divides the input
Nn int Formal parameter in Emirp()
X int Number taken as user input
ans1 int Stores returned number when
the number is passed to
isprime()
ans2 int Stores returned number when
the reverse of the number is
passed to isprime()

Page 48 of 57
OUTPUTS

Page 49 of 57
PROGRAM 8

Page 50 of 57
QUESTION
Write a program to accept a sentence which may be terminated by either ‘.’, ‘?’ or ‘!’ only. The
words are to be separated by a single blank space and are in uppercase. Perform the following
tasks:

(a) Check for the validity of the accepted sentence.

(b) Convert the non-palindrome words of the sentence into palindrome words by concatenating
the word by its reverse (excluding the last character).

Example:

The reverse of the word HELP would be LEH (omitting the last alphabet) and by concatenating
both, the new palindrome word is HELPLEH. Thus, the word HELP becomes HELPLEH.

Note: The words which end with repeated alphabets, for example ABB would become ABBA
and not ABBBA and XAZZZ becomes XAZZZAX.

[Palindrome word: Spells same from either side. Example: DAD, MADAM etc.]

(c) Display the original sentence along with the converted sentence.

Test your program for the following data and some random data:

Example 1

INPUT:
THE BIRD IS FLYING.

OUTPUT:
THE BIRD IS FLYING.
THEHT BIRDRIB ISI FLYINGNIYLF

Example 2

INPUT:
IS THE WATER LEVEL RISING?

OUTPUT:
IS THE WATER LEVEL RISING?
ISI THEHT WATERETAW LEVEL RISINGNISIR

Example 3

Page 51 of 57
INPUT:
THIS MOBILE APP LOOKS FINE.

OUTPUT:
THIS MOBILE APP LOOKS FINE.
THISIHT MOBILELIBOM APPA LOOKSKOOL FINENIF

Example 4

INPUT:
YOU MUST BE CRAZY#

OUTPUT:
INVALID INPUT

ALGORITHM
Step 1: Start.

Step 2: Import the java.util.* package.

Step 3: Declare your class.

Step 4: Declare a method isPalindrome() of boolean return type which would return true if the
parameter is a palindrome.

Step 5: Declare another method makePalindrome() of String return type which would convert the
non-palindrome words into palindrome words by concatenating each word with its reverse.

Step 6: Declare the main() method.

Step 7: Create an object of the Scanner class.

Step 8: Take a sentence as input from the user and store it in the variable ipStr of String type.

Step 9: If the sentence is not terminated with ‘.’, ‘?’ or ‘!’, display an error message and
terminate the program accordingly.

Step 10: Using the above methods, construct the output and display it.

Step 11: Stop.

Page 52 of 57
SOURCE CODE
import java.util.*;

public class String_Palindrome

public static boolean isPalindrome(String word)

boolean palin = true;

int len = word.length();

for (int i = 0; i <= len / 2; i++)

if (word.charAt(i) != word.charAt(len - 1 - i))

palin = false;

break;

return palin;

public static String makePalindrome(String word)

int len = word.length();

char lastChar = word.charAt(len - 1);

Page 53 of 57
int i = len - 1;

while (word.charAt(i) == lastChar)

i--;

StringBuffer sb = new StringBuffer(word);

for (int j = i; j >= 0; j--)

sb.append(word.charAt(j));

return sb.toString();

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.println("ENTER THE SENTENCE:");

String ipStr = in.nextLine().trim().toUpperCase();

int len = ipStr.length();

char lastChar = ipStr.charAt(len - 1);

if (lastChar != '.'

&& lastChar != '?'

&& lastChar != '!')

Page 54 of 57
System.out.println("INVALID INPUT");

return;

String str = ipStr.substring(0, len - 1);

StringTokenizer st = new StringTokenizer(str);

StringBuffer sb = new StringBuffer();

while (st.hasMoreTokens())

String word = st.nextToken();

boolean isPalinWord = isPalindrome(word);

if (isPalinWord)

sb.append(word);

else

String palinWord = makePalindrome(word);

sb.append(palinWord);

sb.append(" ");

String convertedStr = sb.toString().trim();

System.out.println();

Page 55 of 57
System.out.println(ipStr);

System.out.println(convertedStr);

VARIABLE DESCRIPTION
TABLE
boolean isPalindrome():

Variable Data Type Purpose


i int Looping variable
palin boolean Return variable

String makePalindrome():

Variable Data Type Purpose


j int Looping variable

main():

Variable Data Type Purpose


len int Stores length of input String
lastChar char Stores last character of input
ipStr String String input taken from user
str String Stores the string without the
terminating punctuation.
word String Stores the words of the String
convertedStr String Constructed String ; Output
isPalinWord boolean Used in if-statement as
condition variable

Page 56 of 57
OUTPUTS

Page 57 of 57

You might also like