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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:24:05+00:00 2026-05-26T05:24:05+00:00

i have to make a java program (an artichoke cipher) well… please help lol

  • 0

i have to make a java program (an artichoke cipher) well… please help lol

it keeps giving me an error –

 "
    java.lang.StringIndexOutOfBoundsException: String index out of range: 11
    at java.lang.String.charAt(String.java:686)
    at ArtichokeCipher.main(ArtichokeCipher.java:29)
    "

this is the actual artichoke cipher program..i obtain the data file from the user then ask them for the key to be used to shift the letters from the data inside the text file. From there i turn the cipher key into a char to be used as a shift number but im just really lost as to why i get this error.

//PROGRAM
import java.util.Scanner;
import java.io.*;

public class ArtichokeCipher {
public static void main(String[] args) throws IOException {
    Scanner scan1 = new Scanner (System.in);

    System.out.println("Welcome to Artichoke Cipher!");
    System.out.println("Please name input file to be processed: ");
    String filei = scan1.next();
    Scanner scan = new Scanner (new File (filei));

    System.out.println("Please enter the word to be used as the cipher key: ");
    String shift = scan1.next();
    String lowcase = shift.toLowerCase();


    while (scan.hasNext()) {
    String word = scan.nextLine();
    String answer = "";
    for (int i = 0; i < word.length(); i++)
    {
       char curChar = word.charAt(i);
       char key = lowcase.charAt(i);
       char newChar = (char)(curChar + key);
       if (curChar >= 'A' && curChar <= 'Z'){
           if (newChar > 'Z')
           newChar = (char)(newChar-26);
        }
        else if (curChar >= 'a' && curChar <= 'z') {
            if (newChar > 'z')
            newChar = (char)(newChar - 26);
    }
}
            System.out.println("Encoded: " + answer);
}
}
}

any help is appreciated thanks

  • 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-05-26T05:24:06+00:00Added an answer on May 26, 2026 at 5:24 am

    You are potentially overrunning a string on this line:

    char key = lowcase.charAt(i);
    

    The reason is that the index i is valid for word, but may be beyond the length of lowcase. In which case, you will can an Out of Bounds exception when word is longer than lowcase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make a java program installable? I have an application saved in
I am designing a psychology experiment with java applets. I have to make my
I have a Java application and I would like to make it extensible. To
I have a medium size Java file. Everytime I make a change to one
If I want to make my Java program to be able accept plugins, how
I have a simple Java program which reads a file directory and outputs a
I want to know how I can make a Java program where an unknown
i'm trying to make a simple Java program to open an existing word-document, change
I have a java program that I am trying to generate 3 outputs for,
String fileToBeRead = C:/Documents and Settings/Developer/Desktop/Anand exmps/Anand.xls; I have completed a java program in

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.