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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:53:09+00:00 2026-05-25T09:53:09+00:00

i am working on a small java program, its very basic and one of

  • 0

i am working on a small java program, its very basic and one of my functions shifts the alphabet by a given key. i have got it working, but its shifting the wrong way, how can i make it shift the other direction?

public static char[] ourAlphabet = {'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'};


    public  char[] shiftAlphabet(int key) {

            int length = ourAlphabet.length;

            char[] result = new char[length];

            for (int i=0; i < length; i++)
            {
                result[(i+key+26)%length] = ourAlphabet[i];
            }

            return result;
    }

Im guessing its very simple, but its confused me!

For example;
with a key 19 produces;
hijklmnopqrstuvwxyzabcdefg

when is should produce;
TUVWXYZABCDEFGHIJKLMNOPQRS

  • 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-25T09:53:09+00:00Added an answer on May 25, 2026 at 9:53 am

    It should work if you use result[(i-key+26)%length] = ourAlphabet[i];

    However, if length != 26 this would still give a wrong result.

    I would therefore replace the 26 by length;

    result[(i-key+length)%length] = ourAlphabet[i];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working for two weeks on JamVM, a small but powerful Java
I now have a small java script server working correctly, called by: <?php $handle
I'm working on a small Java project that now connects to a MS SQL
I'm working on a small (java) project where a website needs to maintain a
I'm working on a small UML editor project, in Java, that I started a
is there any small working program for recieving from and sending data to client
Im working on a small application to try out an idea that I have.
I am working on a small application in VB.NET. The program needs administrator privilege
I'm working on a small application in Java that takes a directory structure and
We are a company, working on small and some huge project. Sometimes on one

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.