Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:29:10+00:00 2026-06-13T04:29:10+00:00

Programming language: Java Task: designing a hash function that maps Chinese Strings to numbers

  • 0

Programming language: Java
Task: designing a hash function that maps Chinese Strings to numbers
Problem: correct reading and displaying of Chinese characters

This is a homework question, but I’m not asking how to do it, just having trouble implementing the reading of Chinese characters.

A short description of my task: to design a hash function to map (Chinese) students’ names in our class to their student IDs, and other satellite data (gender, phone and the like).

I’m still thinking about it, but just like other languages, the scope of this involves me using the character encoding of a character to, via the hash function, come up with a unique value, if I’m not mistaken.

Here’s what I have to test the validity of this train of thought:

// test whether console can read chinese characters
Scanner s = new Scanner(System.in);

System.out.print("Please enter a Chinese character: ");
int chi = (int)s.next().toCharArray()[0];

System.out.println("\nThe string entered is " + chi);

If I use a simple System.out.println(“character”) statement, the correct character is displayed.

But as seen above, if I use Scanner to read input, I’ve tried to convert the String into a char array then to its int unicode equivalent, but it comes up with a ridiculous number, and I can’t display it correctly.

I realize I can just use this erroneous value to design a hash function, but for the sake of not creating possible collisions (I don’t know if these produce UNIQUE erroneous values), and for the sake of learning, could you point out how I might unify input of chinese characters across different machines?

Always grateful for your thoughts. 😀

Baggio.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:29:12+00:00Added an answer on June 13, 2026 at 4:29 am

    You are over-thinking this. Every String is already (conceptually) a sequence of characters, including Chinese characters.. Encoding only comes into it when you need to convert it into a bytes, which you don’t need to for your assignment. Just use the String‘s hashcode. In fact, when you create a HashMap<String,YourObject>, that’s exactly what will happen behind the scenes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a scanner for my C/C++/C#/Java/D-like programming language that I'm designing
Programming language: Java Ok, so I want to have a BufferedImage that keeps rotating
I was reading Joshua Bloch's Effective Java Programming Language Guide . He explains static
Facts Database: PostgreSQL (latest) Programming language: Java Problem statement (simplified) We have 2 tables
In JAVA(and in every programming language ever invented), we can not use numbers as
Is the memory model for Java a feature of the Java Programming Language or
I have been programming in Java (my first language) for about six months and
Programming language books usually explain that value types are created on the stack, and
I am familier with java programming language I like to extract the data from
I'm currently learning the C programming language (coming from Java) and I'm a bit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.