Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Stringprograms 1624982376

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

DATE(22.05.

2021)
PROGRAMS
* accept a string and convert the starting letter
of each word in capitals */
import java.util.*;
class count1
{
public static void main(String args[])
{
System.out.println("Please enter a string");
Scanner sc=new Scanner(System.in);
String str="",st;int i;
char ch;
while(true)
{
st=sc.next();
if(st.equals("."))
break;
ch=Character.toUpperCase(st.charAt(0));
str=str+ch+st.substring(1)+" ";
}
System.out.println(str);
}
}

/* to count the frequency of the word "the" in


the given string*/

import java.util.*;
class count2
{
public static void main(String args[])
{
System.out.println("Please enter a string");
Scanner sc=new Scanner(System.in);
String st;int i;
char ch;int c=0;
while(true)
{
st=sc.next();
if(st.equals("."))
break;
if(st.equals("the"))
c++;
}
System.out.println("The frequency of the word the is ::"+c);
}
}
//PALINDROME OR SPECIAL WORD
import java.util.*;
class pali
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string to be checked");
String m=sc.next();
String wd="";
for(int i=0;i<m.length();i++)
{
char ch=m.charAt(i);
wd=ch+wd;
}
if(wd.equals(m)==true)
System.out.println("Palindrome and special word");
else if(m.charAt(0)==m.charAt(m.length()-1))
System.out.println("Not a Palindrome but special word");
else
System.out.println("Neither Palindrome nor special word");
}
}

// to print a word in reverse order


import java.util.*;
class reverse
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a string");
String wd="",st="";
int i;char ch;
st=sc.next();
for(i=0;i<st.length();i++)
{
ch=st.charAt(i);
wd=ch+wd;
}
System.out.println(wd);
}
}

/* to print each word in reverse order in


the given string*/
import java.util.*;
class count3
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a string");
String wd="",st="",str="";int i;
char ch;
while(true)
{
st=sc.next();
if(st.equals("."))
break;
for(i=0;i<st.length();i++)
{
ch=st.charAt(i);
wd=ch+wd;
}
str=str+" "+wd;
wd="";
}
System.out.println(str);
}
}
//COUNT AND PRINT THE NUMBER OF PALINDROME WORDS
/* to print each word in reverse order in
the given string*/
import java.util.*;
class countpali
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a string");
String wd="",st="",str="";int i;
char ch;int count=0;
while(true)
{
st=sc.next();
if(st.equals("."))
break;
for(i=0;i<st.length();i++)
{
ch=st.charAt(i);
wd=ch+wd;
}
if(wd.equals(st))
{
System.out.println(st);
count++;
}
wd="";
}
}
}

//to print all special words

import java.util.*;
class countspe
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a string");
String st="";int i;
char ch1,ch2;int c=0;
while(true)
{
st=sc.next();
if(st.equals("."))
break;
ch1=st.charAt(0);
ch2=st.charAt(st.length()-1);
if(ch1==ch2)
{
System.out.println(st);
c++;
}
}
System.out.println(c);
}
}

// to print all words the start with A or a

import java.util.*;
class countA
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a string");
String wd="",st="",str="";int i;
char ch;
while(true)
{
st=sc.next();
if(st.equals("."))
break;
ch=st.charAt(0);
if(ch=='A'||ch=='a')
System.out.println(st);
}
}
}

// to print all the starting letter of each word

import java.util.*;
class printstarting
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a string");
String st="";int i;
char ch;
while(true)
{
st=sc.next();
if(st.equals("."))
break;
ch=st.charAt(0);
System.out.println(ch);
}
}
}
// printing same letter pair

import java.io.*;
class words7
{
public static void main(String args[])
{
String g="RABBIT CARROT";char ch1,ch2;
int i;
for(i=0;i<g.length()-1;i++)
{
ch1=g.charAt(i);
ch2=g.charAt(i+1);
if(ch1==ch2)
System.out.println(ch1+" "+ch2);
}
}
}

/* INPUT: BEAUTIFUL BEAUTIES


OUTPUT:
EA
AU
EA
AU
I E*/

import java.io.*;
class words6
{
public static void main(String args[])throws IOException
{
String g="BEAUTIFUL BEAUTIES";char ch1,ch2;
int i;
for(i=0;i<g.length()-1;i++)
{
ch1=g.charAt(i);
ch2=g.charAt(i+1);
if((ch1=='A'||ch1=='E'||ch1=='I'||ch1=='O'||ch1=='U')&&(ch2=='A'||
ch2=='E'||ch2=='I'||ch2=='O'||ch2=='U'))
ch1=g.charAt(i);
ch2=g.charAt(i+1);
if(ch2-ch1==1)
System.out.println(ch1+" "+ch2);
}
}
}
// to print initials and surname
class surname
{
public static void main(String args[])
{
System.out.println("Please enter a string");
String g="MOHANDAS KARAMCHAND GANDHI";
String st=""; int i;
int k=g.lastIndexOf(' ');
String s1=g.substring(0,k);
String s2=g.substring(k+1);
System.out.println(s1);
System.out.println(s2);
s1=' '+s1;
for(i=0;i<s1.length();i++)
{
char ch=s1.charAt(i);
if(ch==' ')
st=st+s1.charAt(i+1)+'.';
}
System.out.println(st+s2);
}
}
// print and count the vowels present in a word
import java.util.*;
class words4
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a string");
String g=sc.nextLine();
g=g.toLowerCase();
int i;int c=0;
for(i=0;i<g.length();i++)
{
char ch=g.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
System.out.println(ch);
c++;
}
}
System.out.println(c);
}
}
// count and print the number of vowels present in each word in the sentence
import java.util.*;
class words5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a string");
int c=0,j;String wd="";
while(true)
{
wd=sc.next();
if(wd.equals("."))
break;
c=0; //important
for(j=0;j<wd.length();j++)
{
char ch1=wd.charAt(j);
if(ch1=='a'||ch1=='e'||ch1=='i'||ch1=='o'||ch1=='u')
c++;
}
System.out.println(wd+" "+c);
}
}
}

Pattern Printing
Standard X
1. I
IC
ICS
ICSE

2. COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C

3. P
PR
PRO
PROG
PROGR
PROGRA
PROGRAM

4. J
AA
VVV
AAAA

5. BBBBB
LLLL
UUU
EE
J
import java.io.*;
class pattern1
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Please enter a string");
String g="ICSE";
int i;
for(i=1;i<=g.length();i++)
System.out.println(g.substring(0,i));
}
}

import java.io.*;
class pattern2
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Please enter a string");
String g="COMPUTER";
int i;
for(i=g.length();i>=1;i--)
System.out.println(g.substring(0,i));
}
}

import java.io.*;
class pattern3
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Please enter a string");
String g="PROGRAM";
int i;
for(i=1;i<=g.length();i++)
System.out.println(g.substring(0,i));
}
}

import java.io.*;
class pattern4
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Please enter a string");
String g="JAVA";
int i,j,p=0;
for(i=1;i<=g.length();i++)
{
for(j=1;j<=i;j++)
{
System.out.print(g.charAt(p));
}
System.out.println();
p++;
}
}
}
import java.io.*;
class pattern5
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Please enter a string");
String g="BLUEJ";
int i,j,p=0;
for(i=g.length();i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(g.charAt(p));
}
System.out.println();
p++;
}
}
}

You might also like