Skip to content

Conversation

0xkookoo
Copy link
Contributor

@0xkookoo 0xkookoo commented Apr 4, 2018

No description provided.

/* display the most frequent K words in the file and the times it appear
in the file – shown in order (ignore case and periods) */

public class TopKWords {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary spaces between public, class and the class name.

in = fis.read(); // read one character
boolean notEnd = true; // signal whether is the end of file

while (notEnd) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write simple

while (in != -1) {

}


while (notEnd) {
// when in == -1 means get the end of the file
if (-1 == in) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above. You can avoid this if


fis = new FileInputStream(fileName); // open the file
int in = 0;
StringBuffer sb = new StringBuffer(); // load the word

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of StringBuffer use String

notEnd = false; //if false, end the while loop
}
if (Character.isLetter((char)in)) {
sb.append((char)in); //if get a letter, put it in StringBuffer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use String and the operator +=

// this branch means an entire word has just been read
if (sb.length() > 0) {
//see whether word exists in StringBuffer or not
if (dictionary.containsKey(sb.toString())) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments above. You can avoid .toString()

dictionary.put(sb.toString(), 1);
}
}
sb = new StringBuffer(); //reload the StringBuffer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write instead sb = ""; . See my comments above.

}
}

class CountWords {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this class in another file. Or Write it as inline class. Remove the unnecessary spaces between 'class' and 'CountWords'

);

Scanner input = new Scanner(System.in);
Integer k = new Integer(input.nextLine());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of Integer k = new Integer(input.nextLine()); write int k = input.nextInt();

while (k > list.size()) {
System.out.println("Retype a number, your number is too large");
input = new Scanner(System.in);
k = new Integer(input.nextLine());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read my comment above.

All has been improved according to your advice.
@0xkookoo
Copy link
Contributor Author

0xkookoo commented Apr 8, 2018

All has been improved according to your advice, please check it.

Copy link

@christianbender christianbender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Work!


fis = new FileInputStream(fileName); // open the file
int in = 0;
String s = new String(); // init a empty word

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need new String() you can simply write String s = "";

@@ -19,74 +70,15 @@ public static void main(String[] a) {
);

Scanner input = new Scanner(System.in);
Integer k = new Integer(input.nextLine());
int k = input.nextInt();
while (k > list.size()) {
System.out.println("Retype a number, your number is too large");
input = new Scanner(System.in);
k = new Integer(input.nextLine());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this line k = new Integer(input.nextLine());, too.

@0xkookoo
Copy link
Contributor Author

0xkookoo commented Apr 9, 2018

Done. Also, I request to be a member of your team. I have sent an email for a couple of days but no reply.

@christianbender
Copy link

@Lisanaaa see In the description you will find two email-addresses. Sent your mail to them. greetings

@christianbender christianbender merged commit 43d3a56 into TheAlgorithms:master Apr 11, 2018
@0xkookoo
Copy link
Contributor Author

I have already sent to the first email address a couple days ago, should I sent both?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants