2013年9月23日星期一

Statistical sentence English Chinese word frequency , etc., in the English word frequency statistics in Why consumers can not afford

space has been
public class Test {

/ **
* @ param args
* /


static int CalChinesenum (String s)
{int a;
int count = 0;
for (int i = 0; i {a = s.charAt (i);
if (a> = '\ u4e00' && a <= '\ u9fa5')
count + +;
}
System.out.println (" The number of characters for the " + count);
return count;
}

static int CalEnglishnum (String s)
{
char a;
int flag = 0;
int count = 0;
for (int i = 0; i {
a = s.charAt (i);
if (! (a> = 'a' && a <= 'z' | | a> = 'A' && a <= 'Z'))
flag = 0;
else
if (flag == 0) {
flag = 1;
count + +;
}
}
return count;
}

static void CalEachChinesenum (String s)
{char a;
StringBuffer s1 = new StringBuffer ();
for (int i = 0; i {a = s.charAt (i);
if (a> = '\ u4e00' && a <= '\ u9fa5')
s1.append (a);
}
System.out.println (s1);
for (int j = 0; j {int n = 1;
for (int k = j +1; k {
if (s1.charAt (j) == s1.charAt (k))
{s1.deleteCharAt (k);
n + +;
continue;
}
k + +;
}
System.out.print (s1.charAt (j) + " number is the emergence of " ) ;
System.out.println (n);
}
}

static void FindLongestWord (String s, int n)
{
char a;
int flag = 0;
String [] b = new String [n];
StringBuffer s2 = new StringBuffer ();
for (int i = 0; i {
a = s.charAt (i);
if (! (a> = 'a' && a <= 'z' | | a> = 'A' && a <= 'Z'))
{flag = 0;
s2.append ('');
}
else
{
s2.append (a);
if (flag == 0)
flag = 1;
}
}
String tmp = s2.toString ();
b = tmp.split ("");
s2.delete (0, s2.length ());
int max = b [0]. length ();
for (int j = 1; j {
if (b [j]. length ()> max)
{max = b [j]. length ();
s2.replace (0, max, b [j]);
}
}
System.out.print (" the longest English word is :" + s2);
System.out.println (" Length is " + max);
}

static void CalEachword (String s, int n)
{
char a;
int flag = 0;
String [] b = new String [n];
StringBuffer s2 = new StringBuffer ();
for (int i = 0; i {
a = s.charAt (i);
if (! (a> = 'a' && a <= 'z' | | a> = 'A' && a <= 'Z'))
{flag = 0;
s2.append ("1");
}
else
{
s2.append (a);
if (flag == 0)
flag = 1;
}
}
String tmp = s2.toString ();
b = tmp.split ("1");
System.out.println ("S2 is " + s2);
for (int k1 = 0; k1 System.out.println (b [k1]);
s2.delete (0, s2.length ());
for (int j = 0; j {int n1 = 1;
for (int k = j +1; k if (b [k]. equals (b [j]))
{
b [k] = "1";
n1 + +;
}
if (! b [j]. contains ("1"))
{System.out.print (" word :" + b [j]);
System.out.println (" number of occurrences is " + n1);
}
}

}
public static void main (String [] args) {
/ / TODO Auto-generated method stub
String s = "I am a student he is a student hah hah hahn you are a student student student students learn to learn " ;
System.out.print (" Enter the number of characters " ) ;
System.out.println (s.length ());
System.out.println (" number is the English word " + CalEnglishnum (s));
CalChinesenum (s);
CalEachChinesenum (s);
FindLongestWord (s, CalEnglishnum (s));
CalEachword (s, CalEnglishnum (s));
}
}
English word statistical output after the second last line of this note which is why ah ah ah ah ah ?

------ Solution ------- -------------------------------------


compete with each other what is still a good bet , have an incentive to drill a drill !
------ For reference only ---------------------------------------
split split time with ; "1 + " try.
------ For reference only -------------------------------------- -
major bragging I told my students that I can do without regex out now really regret
------ For reference only ------------- --------------------------
here to add a count

static void CalEachword (String s, int n) {
char a;
int flag = 0;
int count = 0 ;/ / b = tmp.split ("1");, even if there are four one three spaces will appear along with spaces even if the time together just add a one
String [] b = new String [n];
StringBuffer s2 = new StringBuffer ();
for (int i = 0; i a = s.charAt (i);
if (! (a> = 'a' && a <= 'z' | | a> = 'A' && a <= 'Z')) {
flag = 0;
if (count == 0) {
s2.append ("1");
count + +;
}

} else {
count = 0;

s2.append (a);
if (flag == 0)
flag = 1;
}
}

没有评论:

发表评论