I have been trying to calculate the value of each letter within a string input by the user (firstname which is then transferred to firstname1 after conversion to lowercases) in order to then add the total to the sum of an int and a double (ageWeight).
I am facing issues with the for loop which does not seem to work (without it I get a final result which does not include the value of the string, but the code at least runs to the end) as I get an error in the console (Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 8).
Eclipse does not give me any error that prevents me from running the codes, so I'm a bit confused as to where in the for loop (or its structure) am I wrong. I've been looking at all sorts of things online and can't get anywhere.
Here is my entire code (before you give a low score which may block me from asking questions, please note that I do not expect anyone to do my work for me, we just don't all have the same level of understanding):
Scanner input = new Scanner(System.in);
System.out.println("Please enter your firstname: ");
String firstname = input.next();
firstname.toLowerCase();
String firstname1 = firstname.toLowerCase();
String alphabet = "abcdefghijklmnopqrstuvwxyz";
int nameValue = alphabet.indexOf(firstname1);
int name = 0;
for (int i=0; i <= firstname1.length(); i++)
{
name = firstname1.charAt(i);
}
System.out.println("Please enter your age: ");
int int1 = input.nextInt();
System.out.println("Please enter your weight: ");
double db = input.nextDouble();
double ageWeight = (int1 + db);
double total = ((ageWeight + name) +1);
System.out.println(total);
}