Posts

Showing posts from January 24, 2014

Printing Consecutive alphabets in a String

import java.io.*;
import java.lang.*;

class s

{
public void asc(String t)
{
 t=t.toUpperCase();


int p,f=0,q,d;

for(int i=65;i<=90;i++)
{
f=0;

for(int j=0;j<t.length()-1;j++)
{
p=(int)t.charAt(j);
q=(int)t.charAt(j+1);

d=q;
if(d==65)
d=91;

if((p==i)&&(d==i+1))
{

f+=1;

System.out.println((char)p+","+(char)q);

}

}
}

}

}


class Cons
{
public static void main(String args[])throws Exception
{
s ob=new s();
DataInputStream d = new DataInputStream(System.in);
String t;
System.out.println("Enter a String");
t= d.readLine();
ob.asc(t);

}
}

Frequency of alphabets in a string

import java.io.*;
import java.lang.*;

class s

{
public void asc(String t)
{

int p,f=0;

for(int i=65;i<=90;i++)
{
f=0;
for(int j=0;j<t.length();j++)
{
p=(int)t.charAt(j);
if((p==i)||(p==i+32))
f+=1;

}
if(f!=0)
System.out.println("FREQUENCY OF "+(char)i+" is "+f+"\t times" );
}

}

}


class Fre
{
public static void main(String args[])throws Exception
{
s ob=new s();
DataInputStream d = new DataInputStream(System.in);
String t;
System.out.println("Enter a String");
t= d.readLine();
ob.asc(t);

}
}