fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import com.google.common.hash.Hashing;
  7. import java.nio.charset.StandardCharsets;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Main {
  11. public static void main(String[] args) {
  12. String uuidStr = "safad";
  13.  
  14. // 使用 MurmurHash32 计算哈希值
  15. int hash = Hashing.murmur3_32()
  16. .hashString(uuidStr, StandardCharsets.UTF_8)
  17. .asInt();
  18. // 取模并确保非负数
  19. int ma = Math.abs(hash % 2);
  20. System.out.println(ma);
  21. }
  22. }
Success #stdin #stdout 0.12s 54928KB
stdin
Standard input is empty
stdout
1