JAVA .REPLACE
JAVA STRING .REPLACE
/*
5. WAP in Java to print when letters and corresponding
frequency in a sentence.
*/
import java.util.*;
class Test
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String name;
System.out.print("\nENTER ANY NAME: ");
name=sc.nextLine();
String ns2=(name.charAt(0)+". ");
String ns="";
int i=0,j=1;
int sch=0;
name.toLowerCase();
int len=name.length();
name.toLowerCase();
System.out.print("\n"+name+"\n");
String s;
char n;
char m2=' ';
while(i<len)
{
name=name.replace(m2,' ');
sch=1;
n=name.charAt(i) ;
s=Character.toString(n);
j=i+1;
while(j<len)
{
char m=name.charAt(j);
if(m==n)
{ sch+=1;
m2=m;
}
j++;
}
if(n!=' ')
System.out.print("\n "+n+" : "+sch);
i++;
}
}
}
Comments
Post a Comment