Sub string
for( c = 0 ; c < length ; c++ )
{
for( i = 1 ; i 0)
l-=c;
}
System.out.println(“Original String: ”+org);
System.out.println(“String after removing duplicates: ”+s);
}
}
Finding the occurrence of a given letter in the inputted
string in java:
import java.io.*;
class check
{void input()throws IOException
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter a sentence”);
String s=br.readLine();
System.out.println(“Enter the letter “);
char a=(char)br.read();
int len=s.length();int c=0;char x;
for(int i=0;i
{ x=Character.toLowerCase(s.charAt(i));
if(x==a)
c=c+1;
}
System.out.println(“Frequency of the letter ’”+a+”‘ in the sentence ‘”+s+”‘ is “+c);
}
}
…………………………………………………………………………………………………………………………………………………………………………….
Program in java to accept a string and print each character
of the string along with its ASCII code:
class Ascii
{void word(String s)
{ int len=s.length();int a;char a1;
for(int i=0;i
{ a1=s.charAt(i);
a=a1;
System.out.println(a1+”–>”+a);
}
}
}
………………………………………………………………………………………………………………………………………………
Program to input name, middle name and surname of a person and print only the initials:
import java.io.*;
class Name
{
void input()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter your name”);
String s=br.readLine(),s1=”";
s=” “+s;
int len=s.length();
char a;
for(int i=0;i
{
a=s.charAt(i);
if(a==’ ‘ )
s1=s1+s.charAt(i+1)+”.”;
}
System.out.println(“Initials are ” + s1);
}
}
…………………………………………………………………………………………………………………………………………………………………………………………………………..
Program to input name, middle name and surname of a person and print the...