I am writing a hashing table and have narrowed down where the issue is coming from.
void put(String word, int line)
{
boolean flag = true;
int val = getValue(word);
val = val%10;
System.out.println(val);
while ( flag )
{
if( total >= words.length )
{
System.out.println("2");
if( words[val] == null )
{
System.out.println("3");
total++;
words[val] = new Word(word);
words[val].addLine(line);
System.out.println(word);
flag = false;
}
else if ( words[val].equals(word) )
{
System.out.println("4");
words[val].addOne();
words[val].addLine(line);
flag = false;
}
val++;
if ( val == words.length )
val=0;
System.out.println("5");
}
}
System.out.println("2");
}
It will only print out val, then continue to give me a loading sign. Is there something wrong with the loop perhaps? But if so why wouldn’t it atleast print out 2-5? Any advice would really be appreciated.
You don’t show us the complete code but from what I can see the only explanation is that you are inside the loop but the outmost if-condition
total >= words.lengthis never fulfilled.Thus your code is running in an infinite loop without doing anything usefull at all.