docs(Others): update countwords.java and crc32.java
- By @yanglbme
This commit is contained in:
parent
2ceb1aa907
commit
c516834ed6
@ -1,13 +1,12 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* You enter a string into this program, and it will return how
|
||||
* many words were in that particular string
|
||||
* You enter a string into this program, and it will return how many words were
|
||||
* in that particular string
|
||||
*
|
||||
* @author Marcus
|
||||
*
|
||||
*/
|
||||
public class countwords{
|
||||
public class CountWords {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
@ -19,7 +18,8 @@ import java.util.Scanner;
|
||||
}
|
||||
|
||||
private static int wordCount(String s) {
|
||||
if(s.isEmpty() || s == null) return 0;
|
||||
if (s == null || s.isEmpty())
|
||||
return 0;
|
||||
return s.trim().split("[\\s]+").length;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
import java.util.BitSet;
|
||||
|
||||
//Generates a crc32 checksum for a given string or byte array
|
||||
public class crc32 {
|
||||
/**
|
||||
* Generates a crc32 checksum for a given string or byte array
|
||||
*/
|
||||
public class CRC32 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Integer.toHexString(crc32("Hello World")));
|
||||
@ -16,7 +18,7 @@ public class crc32 {
|
||||
int crc32 = 0xFFFFFFFF; // initial value
|
||||
for (int i = 0; i < data.length * 8; i++) {
|
||||
if (((crc32 >>> 31) & 1) != (bitSet.get(i) ? 1 : 0))
|
||||
crc32 = (crc32 << 1) ^ 0x04C11DB7; //xoring with polynomial
|
||||
crc32 = (crc32 << 1) ^ 0x04C11DB7; // xor with polynomial
|
||||
else
|
||||
crc32 = (crc32 << 1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user