0% found this document useful (0 votes)
7 views3 pages

KISA Programs

Uploaded by

Jathin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

KISA Programs

Uploaded by

Jathin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

//Removing double letter s from the given string

import java.util.*;
public class removingdoubleletter
{
public static void main(String args[])

{
Scanner sc=new Scanner(System.in);
String str,str1="";
System.out.println("enter a string");
str=sc.nextLine();
char ch=' ';

int len=str.length();
for(int i=0;i<len;i++)
{

char ch1=str.charAt(i);
if(ch!=ch1)
{

str1=str1+ch1;
ch=ch1;

}
System.out.println("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 java.util.*;
public class encode
{
public static void main(String args[])
{

Scanner sc=new Scanner(System.in);


String str,str1="";
System.out.println("enter a string");
str=sc.next();
str=str.toLowerCase();
int len=str.length();
for(int i=0;i<len;i++)
{
char ch=str.charAt(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
System.out.println("the accepted"+str);
System.out.println("the encoded"+str1);
}
}

Output:
enter a string
computerrAAXYZ
the accepted computerraaxyz
the encoded eqorwvgttcczab

You might also like