This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

hash problem  RSS feed

 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all i am trying to use an array to store names using a hash index when i run it i just get null for the result can anybody help me on this here is the code i have written:

public class Test
{

/**
* @param args
*/
public static void main(String[] args)
{
int numOfStudents=5;
String name;
int str = 0;
int hash;
String[] store = new String[numOfStudents];
for(int i=0; i<numOfStudents; i++)
{
name = JOptionPane.showInputDialog("plese enter a name");
str = name.toUpperCase().charAt(i);
}
hash = str % numOfStudents;
for(int i=0; i<store.length; i++)
{
System.out.println(store[i]);
}
}

}
 
Philip Heller
author
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see where you're storing anything in the store[] array, so you're printing out the default null contents.

What did you intend to do with hash?
 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi philip
sorry about that i had been messing about with the code and left it out when i cut and pasted it any way what i am trying to do is create an array that uses the hash index when storing names from the JOptionPane the number of entries set at 5. i have to use the toUpperCase() method and the charAt() and store the names in the array then print all the names to the screen but i just cannot seem to get it right.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!