0% found this document useful (0 votes)
27 views4 pages

Strings (ALL PROGRAMS)

1) The document contains the code for a Java class with multiple methods that perform string operations and analysis. 2) Each method prompts the user to input a string, performs some operation on the string like checking for vowels/consonants, reversing words, etc. 3) The operations include checking for palindromes, counting characters in a string, extracting initials from a name, converting to Pig Latin, and more.

Uploaded by

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

Strings (ALL PROGRAMS)

1) The document contains the code for a Java class with multiple methods that perform string operations and analysis. 2) Each method prompts the user to input a string, performs some operation on the string like checking for vowels/consonants, reversing words, etc. 3) The operations include checking for palindromes, counting characters in a string, extracting initials from a name, converting to Pig Latin, and more.

Uploaded by

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

import java.util.

*;
public class Class14{
static Scanner in =new Scanner(System.in);
String s1;
public static void SpecialWord(){
System.out.println("Enter String");
String s= in.nextLine();
if(s.charAt(0)==s.charAt(s.length()-1))
System.out.println("SPECIAL WORD");
else
System.out.println("NOT A SPECIAL WORD");
}
public static void VowelsConsonants(){
System.out.println("Enter String");
String s= in.nextLine();
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
System.out.println("VOWELS ARE");
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||
ch=='I'||ch=='O'||ch=='U')
{
System.out.println(ch);
}
}
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
System.out.println("CONSONANTS ARE:");
if(ch!='a'&&ch!='e'&&ch!='i'&& ch!='o'&& ch!='u'&& ch!='A'&& ch!='E'&&
ch!='I'&& ch!='O'&& ch!='U')
{
System.out.println(ch);
}
}
}
public static void FrequencyVowels(){
System.out.println("Enter a string");
String s= in.nextLine();
int c=0;
for(int i=0;i<s.length();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')
{
c++;
}
System.out.println("Frequency of vowels are:"+c);
}
}
public static void Palindrome(){
System.out.println("Enter a string");
String s= in.nextLine();
String word="";
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
word= ch+word;
}
if(word.equals(s))
{
System.out.println("PAlindrome String");
}
else
System.out.println("Not a palindrome string");
}
public static void firstLetterEachWord(){
System.out.println("Enter a word");
String s= in.nextLine();
s=" "+s;
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
if(ch==' ')
{
System.out.println(s.charAt(i+1));

}
}
}
public static void lastLetterEachWord(){
System.out.println("Enter a word");
String s= in.nextLine();
s=" "+s;
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
if(ch==' ')
System.out.println(s.charAt(i-1));
}
}
public static void NameInitialSurname(){
System.out.println("Enter a name");
String s=in.nextLine();
int lst= s.lastIndexOf(' ');
s=" "+s;
for(int i=0;i<lst;i++)
{
char ch= s.charAt(i);
if(ch==' ')
{
System.out.print(s.charAt(i+1)+".");
}
}
System.out.println(s.substring(lst+1));
}
public static void CountEachParameter(){
System.out.println("Enter a sentence");
String s= in.nextLine();
int u=0,l=0,d=0,sp=0;
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
if(Character.isUpperCase(ch))
u++;
if(Character.isLowerCase(ch))
l++;
if(Character.isDigit(ch))
d++;
if(Character.isWhitespace(ch))
sp++;
}
System.out.println("NUMBER OF UPpERCASE LETTERS: "+u);
System.out.println("NUMBER OF LOWERCASE LETTERS: "+l);
System.out.println("NUMBER OF DIGITS: "+d);
System.out.println("NUMBER OF SPACES: "+sp);
}
public static void Piglatin(){
System.out.println("Enter a word");
String s= in.next();
s=s.toUpperCase();
int i;
for( i=0;i<s.length();i++)
{
char ch= s.charAt(i);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
{
break;
}
}
System.out.print(s.substring(i));
System.out.print(s.substring(0,i)+"AY");
}
public static void ToggleCase(){
System.out.println("Enter a string");
String s= in.nextLine();
String word="";
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
if(Character.isUpperCase(ch))
ch= Character.toLowerCase(ch);
if(Character.isLowerCase(ch))
ch= Character.toUpperCase(ch);
word= word+ch;
}
System.out.println(word);
}
public static void Capital1stLEtter(){
System.out.println("Enter a String");
String s= in.nextLine();
s= " "+s;
String word="";
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
if(ch==' ')
{
ch= Character.toUpperCase(s.charAt(i+1));
i++;
word=word+" ";
}
word= word+ch;
}
System.out.println(word.trim());
}
public static void LongestWord(){
System.out.println("Enter a Sentence");
String s= in.nextLine();
int sp=0;
String w="";
s=s+" ";
String lo="",mix="";
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
if(ch==' ')
{
if(mix.length()>lo.length())
lo=mix;
mix="";
}
else
mix=mix+ch;
}
System.out.println("Longest word="+lo);
}
public static void RemoveVowls(){
System.out.println("Enter a string");
String s= in.nextLine();
char ch;String w="";
for(int i=0;i<s.length();i++)
{
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')
continue;
else
w=w+ch;
}
System.out.println("VOWEL FREE STRING: "+w);
}
public static void reverseSentence(){
System.out.println("Enter a sentence");
String s= in.nextLine();
s=s+" ";
String w="";
String rev="";
for(int i=0;i<s.length();i++)
{
char ch= s.charAt(i);
if(ch!=' ')
{
w=ch+w;
}
else if(ch==' ')
{
rev=rev+w+" ";
w="";
}
}
System.out.println("REVERSED WORD: "+rev);
}
}

You might also like