i have a program that converts a text string into a hash sequence using parseInt(). but parseInt() keeps throwing a NumberFormatException.
any ideas why? is it becuase i'm using <= instead of = in my for loop?
EDIT: ingnore r. it's not being used. sorry.
package test;
import java.util.Random;
import java.util.Scanner;
public class minecraft_check {
public static void main(String[] args)
{
String yn = null;
Random rand = new Random();
String r = null;
int hash = 0;
do
{
do
{
System.out.print("Enter the Seed to be converted (max 30 chars.): ");
r = new Scanner(System.in).nextLine();
}
while(r.length() > 31);
hash = getHashCode(r, rand);
System.out.println("\nYour Hash code for " + r + " is: " + hash + "\n\n");
System.out.println("Again? (y/n)");
yn = new Scanner(System.in).nextLine();
}while(yn != "n" && yn != "N");
System.exit(0);
}
public static int getHashCode(String seed, Random rand)
{
char[] split = seed.toCharArray();
int generatornum = 0, r = 0;
for(int i = 0; i <= seed.length();)
{
r = rand.nextInt(256);
if(!(r == 0 || r == 256))
{
generatornum+=(Integer.parseInt(Integer.toString((int)split[i]), 256)) * Math.pow(31,seed.length()-i);
i++;
}else continue;
}
return generatornum;
}
}