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 8505441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:19:08+00:00 2026-06-11T02:19:08+00:00

Near the end of my program I have turned my user input into a

  • 0

Near the end of my program I have turned my user input into a chararray called letter. I want to iterate through letter and for each “letter” in the array, I would like to add or subtract the value of shiftCode. shiftCode can be a positive or a negative. I have a small part that functions where it simply adds 1 to the first letter of “letter”.

Can someone please tell me how to use i++ in order to iterate through each letter in letter and add or subtract using shiftCode value?

I THINK it will look something like

for(shiftCode; shiftCode === 26; shiftCode++) {
     letter[EVERY LETTER IN THIS THING?] += shiftCode;
}

I can’t seem to figure out how to iterate for the value of shiftCode through each letter. If someone could point me in the right direction I would greatly appreciate it.

Thank you,
Aaron

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
 * This program is designed to -
 * Work as a Ceasar Cipher
 */

/**
 *
 *
 */
public class Prog3 {
    static String codeWord;
    static int shiftCode;
    static int i;
    static char[] letter;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // Instantiating that Buffer Class
        // We are going to use this to read data from the user; in buffer
        // For performance related reasons
        BufferedReader reader;

        // Building the reader variable here
        // Just a basic input buffer (Holds things for us)
        reader = new BufferedReader(new InputStreamReader(System.in));

        // Java speaks to us here / We get it to query our user
        System.out.print("Please enter text to encrypt: ");

        // Try to get their input here
        try {    
            // Get their codeword using the reader
            codeWord = reader.readLine();

            // What ever they give us is probably wrong anyways.
            // Make that input lowercase
            codeWord = codeWord.toUpperCase();
            letter = codeWord.toCharArray();
        }
        // If they messed up the input we let them know here and end the prog.
        catch(Throwable t) {
            System.out.println(t.toString());
            System.out.println("You broke it. But you impressed me because"
                    + "I don't know how you did it!");
        }

        // Java Speaks / Lets get their desired shift value
        System.out.print("Please enter the shift value: ");

        // Try for their input
        try {
               // We get their number here
               shiftCode = Integer.parseInt(reader.readLine());
        }
        // Again; if the user broke it. We let them know.
        catch(java.lang.NumberFormatException ioe) {
            System.out.println(ioe.toString());
            System.out.println("How did you break this? Use a number next time!");
        }
        letter[1] += 1;
        System.out.println(letter[1]);
    }
}
  • 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-11T02:19:09+00:00Added an answer on June 11, 2026 at 2:19 am

    Here’s one way that you can iterate over an array.

        for(int i = 0; i < letter.length; i++) {
            // using i, you can manipulate and access all elements of the array.
            letter[i] -= shiftCode; // may want more logic in this case.
        }
    

    I also notice that you don’t handle the error condition well; you should wrap all of the code that deals with reader inside of the try...catch block.

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

Sidebar

Related Questions

I'm near the end of a program I had got to code for my
at the start and end of my program, I have from time import strftime
I'm running a Java (.jar) program from a bat script that near the end
Let's assume one joins a project near the end of its development cycle. The
In the near future, my organisation will have to change both the machine name
I have near about 255 image frames for background animation, 99 frames of enemy
I have a text field that is near the bottom of the screen. When
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
I want to write a stored proc which iterates through all of the tables
The other day I was converting a program written with C99 standard into C11.

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.