//Removing double letter s from the given string
import [Link].*;
public class removingdoubleletter
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
String str,str1="";
[Link]("enter a string");
str=[Link]();
char ch=' ';
int len=[Link]();
for(int i=0;i<len;i++)
{
char ch1=[Link](i);
if(ch!=ch1)
{
str1=str1+ch1;
ch=ch1;
}
[Link]("new string is"+str1);
}
}
Output:
enter a string
Comppputtterrr Applicationsss
new string isComputer Aplications
2. Write a program in Java to accept a String and convert it into lowercase and encode the string
with +2 character. Print the accepted and encoded string.
import [Link].*;
public class encode
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
String str,str1="";
[Link]("enter a string");
str=[Link]();
str=[Link]();
int len=[Link]();
for(int i=0;i<len;i++)
{
char ch=[Link](i);
if(ch=='y')
ch='a';
else if(ch=='z')
ch='b';
else
ch=(char)(ch+2);//end of else
str1=str1+ch; //part of for loop
}//ending for loop
[Link]("the accepted"+str);
[Link]("the encoded"+str1);
}
}
Output:
enter a string
computerrAAXYZ
the accepted computerraaxyz
the encoded eqorwvgttcczab