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

  • SEARCH
  • Home
  • 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 8212837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:54:20+00:00 2026-06-07T10:54:20+00:00

import java.util.*; import java.util.Arrays; public class ScoreCalc { public static void main(String[] args) {

  • 0
import java.util.*;

import java.util.Arrays;

public class ScoreCalc {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        int[] score = {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};
        System.out.println("Enter word: ");
        String word = in.nextLine();
        int totalScore = 0;
        char[] wordArray = word.toCharArray();
        for(int i=0; i<wordArray.length; i++) {
            System.out.println(wordArray[i]);
            int index = Arrays.asList(alphabet).indexOf(wordArray[i]);
            System.out.println(index);
            totalScore = totalScore + score[index];
        }
        System.out.println(totalScore);
    }
}

This keeps coming up with Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: -1

Because it can’t find any of the characters in the array alphabet can someone help plz!

  • 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-07T10:54:21+00:00Added an answer on June 7, 2026 at 10:54 am

    indexOf(wordArray[i]) is returning -1. I suspect this is due to uppercase letters and/or special characters. Do this first and add error checking:

    word.toLowerCase().toCharArray()
    

    Regardless, I would do something like this instead as it’s much cleaner:

    String alphabet = "abcdefghijklmnopqrstuvwxyz";
    

    and then

    int index = alphabet.indexOf(wordArray[i]);
    if(index == -1) {
        // handle the special character
    } else {
        totalScore += score[index];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code: import java.util.Scanner; public class Arrays { public static void main(String[] args)
import java.util.Arrays; public class Test { public static void main(String... args) { String[] strings
import java.io.UnsupportedEncodingException; import java.util.Arrays; public class Main { public static void main(String[] args) {
import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class Filereader { public static void main(String[]
import java.io.*; import java.util.*; public class Readfilm { public static void main(String[] args) throws
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class InversionCounter { public static void main(String[]
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateDemo { public static void main(String[]
package javaLearning; import java.util.Arrays; import java.util.Collections; public class myarray { public static void name()
package homework5; import java.io.*; import java.util.Arrays; public class Main { /** * @param args
import java.util.Arrays; import java.util.ArrayList; import java.util.Scanner; import java.util.Collections; import java.util.List; public class TennisTournament {

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.