File tree Expand file tree Collapse file tree 2 files changed +31
-29
lines changed Expand file tree Collapse file tree 2 files changed +31
-29
lines changed Original file line number Diff line number Diff line change 11import java .util .Scanner ;
22
33/**
4- * You enter a string into this program, and it will return how
5- * many words were in that particular string
6- *
7- * @author Marcus
4+ * You enter a string into this program, and it will return how many words were
5+ * in that particular string
86 *
7+ * @author Marcus
98 */
10- public class countwords {
9+ public class CountWords {
1110
12- public static void main (String [] args ){
13- Scanner input = new Scanner (System .in );
14- System .out .println ("Enter your text: " );
15- String str = input .nextLine ();
16-
17- System .out .println ("Your text has " + wordCount (str ) + " word(s)" );
18- input .close ();
19- }
11+ public static void main (String [] args ) {
12+ Scanner input = new Scanner (System .in );
13+ System .out .println ("Enter your text: " );
14+ String str = input .nextLine ();
2015
21- private static int wordCount (String s ){
22- if (s .isEmpty () || s == null ) return 0 ;
23- return s .trim ().split ("[\\ s]+" ).length ;
24- }
25-
16+ System .out .println ("Your text has " + wordCount (str ) + " word(s)" );
17+ input .close ();
2618 }
19+
20+ private static int wordCount (String s ) {
21+ if (s == null || s .isEmpty ())
22+ return 0 ;
23+ return s .trim ().split ("[\\ s]+" ).length ;
24+ }
25+
26+ }
Original file line number Diff line number Diff line change 11import java .util .BitSet ;
22
3- //Generates a crc32 checksum for a given string or byte array
4- public class crc32 {
5-
3+ /**
4+ * Generates a crc32 checksum for a given string or byte array
5+ */
6+ public class CRC32 {
7+
68 public static void main (String [] args ) {
79 System .out .println (Integer .toHexString (crc32 ("Hello World" )));
810 }
9-
11+
1012 public static int crc32 (String str ) {
1113 return crc32 (str .getBytes ());
1214 }
13-
15+
1416 public static int crc32 (byte [] data ) {
1517 BitSet bitSet = BitSet .valueOf (data );
16- int crc32 = 0xFFFFFFFF ; // initial value
17- for (int i = 0 ; i < data .length * 8 ; i ++) {
18- if (((crc32 >>>31 )& 1 ) != (bitSet .get (i )? 1 : 0 ))
19- crc32 = (crc32 << 1 ) ^ 0x04C11DB7 ; //xoring with polynomial
18+ int crc32 = 0xFFFFFFFF ; // initial value
19+ for (int i = 0 ; i < data .length * 8 ; i ++) {
20+ if (((crc32 >>> 31 ) & 1 ) != (bitSet .get (i ) ? 1 : 0 ))
21+ crc32 = (crc32 << 1 ) ^ 0x04C11DB7 ; // xor with polynomial
2022 else
2123 crc32 = (crc32 << 1 );
2224 }
23- crc32 = Integer .reverse (crc32 ); // result reflect
24- return crc32 ^ 0xFFFFFFFF ; // final xor value
25+ crc32 = Integer .reverse (crc32 ); // result reflect
26+ return crc32 ^ 0xFFFFFFFF ; // final xor value
2527 }
2628
2729}
You can’t perform that action at this time.
0 commit comments