File tree 2 files changed +31
-29
lines changed
2 files changed +31
-29
lines changed Original file line number Diff line number Diff line change 1
1
import java .util .Scanner ;
2
2
3
3
/**
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
8
6
*
7
+ * @author Marcus
9
8
*/
10
- public class countwords {
9
+ public class CountWords {
11
10
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 ();
20
15
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 ();
26
18
}
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 1
1
import java .util .BitSet ;
2
2
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
+
6
8
public static void main (String [] args ) {
7
9
System .out .println (Integer .toHexString (crc32 ("Hello World" )));
8
10
}
9
-
11
+
10
12
public static int crc32 (String str ) {
11
13
return crc32 (str .getBytes ());
12
14
}
13
-
15
+
14
16
public static int crc32 (byte [] data ) {
15
17
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
20
22
else
21
23
crc32 = (crc32 << 1 );
22
24
}
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
25
27
}
26
28
27
29
}
You can’t perform that action at this time.
0 commit comments