String Based Program
String Based Program
1. While typing a typewriter has made two or more consecutive blank spaces ina a sentence.
Write a program in java to replace two or more consecutive blanks by a single blank
input:
output :
Understanding computer applications for ICSE is written by vijay kumar pandey and Dilip
Kumar Dey.
import java.util.*;
class space
String s=sc.nextLine();
System.out.println(s);
}
2. Write a program to input a sentence in uppercase and frame a word by adding the first
alphabet of each word and also arrange the alphabets of the new word in an alphabetical order
also remove the duplicating alphabets.
output : NMITPMOI
import java.util.*;
class s2
String s=sc.nextLine();
s=s.toUpperCase();
int len=s.length();
for(int i=0;i<len;i++)
char ch=s.charAt(i);
if(ch==' ')
w=w+s.charAt(i+1);
}
char ch=(char)i;
for(int j=0;j<w.length();j++)
char ch1=w.charAt(j);
if(ch1==ch)
w1=w1+ch1;
w1=w1+" ";
int len=w1.length();
char ch=w1.charAt(i);
if(ch==w1.charAt(i+1))
w2=w2+w1.charAt(i+1);
i++;
}
else
w2=w2+ch;
3. Write a program in java to input a string and check the frequency of palindrome words(containing 3
or more characters) in the given string.
output : The three characters or more palindrome words are: MADAM ARORA
import java.util.*;
class revcheck
String s=sc.nextLine();
int len=s.length();
String p="";
int c=0;
for(int i=0;i<len-1;)
char ch=s.charAt(i);
String w="";
while(ch!=' ')
ch=s.charAt(i);
w=w+ch;
i++;
if(w.length()>=3)
String r="";
for(int j=w.length()-1;j>=0;j--)
char ch1=w.charAt(j);
r=r+ch1;
w=w.trim();
r=r.trim();
if(w.equals(r))
c++;
p=p+w+" ";
w="";
4. Write a program to accept a word and count the number of characters to make the word palindrome.
input : DILIP
import java.util.*;
class Rev
String s=sc.nextLine();
int len=s.length();
String w="";
int c=0;
s=s.toUpperCase();
for(int i=len-1;i>=0;i--)
w=w+s.charAt(i);
if(w.charAt(i)!=s.charAt(i))
c++;
Zeal xfbj
program nppepbk
anode blpbf
import java.util.*;
class encrypted
String s=sc.nextLine();
String w="";
int len=s.length();
for(int i=0;i<len;i++)
char ch=s.charAt(i);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'||ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
int m=((int)ch)+1;
w=w+(char)m;
else if(ch!='A'||ch!='E'||ch!='I'||ch!='O'||ch!='U'||ch!='a'||ch!='e'||ch!='i'||ch!='o'||ch!='u')
int m=((int)ch)-2;
w=w+(char)m;
System.out.println("Word"+"\t"+"Encrypted form");
System.out.println("****"+"\t"+"********* ****");