Thursday, November 7, 2019

ISC COMPUTER SCIENCE QUESTION PRACTICAL PAPER 2017| QUESTION NUMBER 3 | Follow on YOUTUBE for more |




import java.util.*;
public class qstn_3
{
public static void main(String[] args)
{
Scanner sc  = new Scanner(System.in);

//Taking user input
System.out.println("Enter the sentence");
String s = sc.nextLine();

//For lowercase characters
String low = "abcdefghijklmnopqrstuvwxyzabcdefghijklm";

//For Uppercase characters
String cap = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM";

//Taking the length of input string
int length = s.length();

//To check for the boundary condition
if(length<4||length>99)
{
System.out.println("INVALID LENGTH");
System.exit(0);
}
//For the new word
String new_word = "";

for(int i=0;i<length;i++)
{
//Extracting
char c = s.charAt(i);

//Checking for the uppercase character
if(Character.isUpperCase(c))
{
//To get the position of the character
//so that you can encode it.
for(int j = 0;j<cap.length();j++)
{

char c1 = cap.charAt(j);

//To compare both the characters
//to check if they are equal
if(c==c1)
{

//Increasing the character by 13 position
char lower_case = cap.charAt(j+13);

//Storing the new character
new_word+=lower_case;//new_word = new_word+lower_case;
break;
}
}
}

//Checking for the lowercase character
else if(Character.isLowerCase(c))
{
//To get the position of the character
//so that you can encode it.
for(int j = 0;j<low.length();j++)
{
char c1 = low.charAt(j);

//To compare both the characters
//to check if they are equal
if(c==c1)
{

//Increasing the character by 13 position
char upper_case = low.charAt(j+13);

//Storing the new character
new_word+=upper_case;
break;
}
}
}

//For exclaimation mark character
else if(c=='!')
{
new_word+="?";
}

//For any other characters
else
{
new_word+=c;
}
}

//Result output
System.out.println("\nThe cipher text is:");
System.out.println(new_word);
}
}

No comments:

Post a Comment

ICSE COMPUTER SCIENCE SPECIMEN PAPER | QUESTION 7 | PLEASE DO WATCH THE VIDEO

  import  java.util.*; class icse_specimen_1 {     public static void main(String[] args)     {         Scanner sc1 = new Scanner(System.in)...