3 Comments

  1. PRASHANT

    what will be code for
    AAAAA
    BBBB
    CCC
    DD
    E

    Reply
  2. jade

    I am a complete beginner in programming and I am having difficulties to solve this problem.
    Each letter is converted to the letter which
    is 3 places after it in the alphabets. For example, A is converted to D.
    The sequence is cyclic, that is, X is converted to A, Y to B and Z to C.
    Write a java program that allows you to input a line of text and
    outputs the encrypted version. The line of text is terminated by a ‘.’.
    This is what I got so far:
    import java.util.scanner
    public class ReplaceString {

    public static void main(String[] args) {
    string str=”Meet me at Times Square tonight.”
    System.out.println(str replace (all letters by the fourth letter found after it in alphabetical order,
    a=d,
    b=e,
    c=f,
    d=g,
    e=h,
    f=i,
    g=j,))
    // loop till alphabetical cycle is complete.
    }
    }
    phhw ph dw wlphv vtxdvh wrqljkw
    please help

    Reply

    • 
        public static String convert(String str) {
          char[] charray = str.toCharArray();
          StringBuilder sb = new StringBuilder(str.length());
          int i = 0;
          while (i < charray.length) {
            if (Character.isLetter(charray[i])) {
              char ch = (char) (charray[i] + 3);
              sb.append(ch);
            } else if ((char) charray[i] == ' ') {
              sb.append(' ');
            }
      
            i++;
          }
          return sb.toString();
        }
      

      Reply

Leave a Reply.. code can be added in <code> </code> tags