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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:43:37+00:00 2026-06-14T20:43:37+00:00

I created this code that looks at a string token and formats it so

  • 0

I created this code that looks at a string token and formats it so that every character is moved along by one. The characters are all lowercase and from a to z.

So if my input is
abcz

Output is
bcda

Right now I added all the alphabets to an arraylist, and the code determines the index of each character and adds one to it. If it finds z, it prints a so that index of the arraylist is not out of range.

List<String> letters = new ArrayList<String>(); 
        String alp = "abcdefghijklmnopqrstuvwxyz";
        for (int i = 0; i<26; i++)
        {
            letters.add(Character.toString(alp.charAt(i)));
        }

        String token = sc.next();
        for (int i = 0; i<token.length(); i++)
        {
            if (letters.get(letters.indexOf(Character.toString(token.charAt(i)))).equals("z"))
            {
                System.out.print("a");
            }
            else
            {
            System.out.print(letters.get(letters.indexOf(Character.toString(token.charAt(i)))+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-14T20:43:38+00:00Added an answer on June 14, 2026 at 8:43 pm

    A simple loop with a bit of modular arithmetic will do, why bother with so many objects?

    for(int i = 0; i < token.length(); ++i) {
        System.out.print(('a' + (token.charAt(i) + 1 - 'a')%('z' - 'a' + 1)));
    }
    

    We increase the offset from 'a' by one, and take the remainder modulo 26 to get an offset in the range from 0 to 25.

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

Sidebar

Related Questions

I've created this code branch so that if the permalink settings do no match
I just found myself writing a piece of code that looks like this: def
I have the this code that will create excel file and work sheet then
Well ive got this code that creates a table from JSON data. If a
Hi I have been working on this code that creates a table with radio
I have this JavaScript code that creates a table, and puts in the rows
I have create a vcf file that contains contacts by using this code ContentResolver
I have this function in a Code Igniter model that creates a new video.
I've created this code, it is supposed to use wordpress metabox functionality to save
I have created this Fiddle with this code: This is my problem I want

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.