Programming Examples

Java program to encrypt the data based on given rules


Encryption is a technique of coding messages to maintain their secrecy. A String array of size ‘n’ where ‘n’ is greater than 1 and less than 10, stores single sentences (each sentence ends with a full stop) in each row of the array.

Write a program to accept the size of the array. Display an appropriate message if the size is not satisfying the given condition. Define a string array of the inputted size and fill it with sentences row-wise. Change the sentence of the odd rows with an encryption of two characters ahead of the original character. Also change the sentence of the even rows by storing the sentence in reverse order. Display the encrypted sentences as per the sample data given below:

Test your program on the sample data and some random data. Example 1 :

INPUT: n = 4

IT IS CLOUDY.

IT MAY RAIN.

THE WEATHER IS FINE. IT IS COOL.

OUTPUT: KV KU ENQWFA.

RAIN MAY IT.

VJG YGCVJGT KU HKPG. COOL IS IT.

Example 2 :

INPUT: n = 13

OUTPUT: INVALID ENTRY

Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz