Hamlet feedback a bitter tear

Source: Internet
Author: User

In my long-time efforts I finally finished the simple task, I tried several methods, finally succeeded, but also drunk.

In order to be able to display the most occurrences of the letter and the number of times, I have a mistake after the use of a similar two-paragraph program, I succeeded.

Import Java.io.BufferedReader;
Import Java.io.File;
Import java.io.FileNotFoundException;
Import Java.io.FileReader;
Import java.io.IOException;
public class Count {
public static void Main (string[] args) {
String Path = "C:/users/86173/desktop/englishartical.txt";
File File = new file (path);
Int[] Count=new int[26];
Int[] Count2=new int[26];
for (int i=0;i<26;i++)
{
Char a= ' a ';
int n= ((int) a+i);
Char des = (char) n;
int count1 = Process (file, DES);
Count[i]=count1;
System.out.println ("character" + des + "in the presence of" + count[i]+ "Times");
}
for (int i=0;i<26;i++)
{
Char a= ' a ';
int n= ((int) a+i);
Char des = (char) n;
int count1 = Process (file, DES);
Count2[i]=count1;
System.out.println ("character" + des + "appears" + count2[i]+ "Times");
}
int j=0,k=0;
int maxIndex1 = count[0];
int minIndex1 = count[0];
for (int i = 0; i < count.length; i++) {
if (MaxIndex1 < count[i]) {
MaxIndex1 = Count[i];
J=i;
}
if (MinIndex1 > Count[i]) {
MinIndex1 = Count[i];
}
}
int maxIndex2 = count2[0];
int minIndex2 = count2[0];
for (int i = 0; i < count2.length; i++) {
if (MaxIndex2 < count2[i]) {
MaxIndex2 = Count2[i];
K=i;
}
if (MinIndex2 > Count2[i]) {
MinIndex2 = Count2[i];
}
}

if (MAXINDEX1&GT;MAXINDEX2)
{char a= ' a ';
int n= ((int) a+j);
Char des = (char) n;
System.out.println ("character" + des + "occurs at most times:" +maxindex1);
}
else if (MAXINDEX1&LT;MAXINDEX2)
{char a= ' a ';
int n= ((int) a+k);
Char des = (char) n;
System.out.println ("character" + des + "occurs at most times:" +maxindex2);
}


}

public static int process (file file, char c) {
int count = 0;
BufferedReader br = null;
try {
br = new BufferedReader (new FileReader (file));
String temp = "";
while (temp = br.readline ()) = null) {
char[] des = Temp.trim (). ToCharArray ();
for (int i = 0; i < des.length; i++) {
if (des[i] = = c) {
count++;
}
}
}
} catch (FileNotFoundException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
} finally {
try {
Br.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
return count;
}
}

Hamlet feedback a bitter tear

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.