package casesar02;

import java.util.Scanner;

public class casesar02

{


public static void main(String[] args)

{

          Scanner scan = new Scanner(System.in);
          int key = 4;
         // scan.nextLine();
         String str = scan.nextLine();


         String encrypted = encrypt(str, key);
         System.out.println(encrypted);
        }

    public static String encrypt(String str, int key) {

        String encrypted = "";

        for (int i = 0; i < str.length(); i++) {

            int c = str.charAt(i);

            if (Character.isUpperCase(c)) {

                if(c < 'C')
                {

                    c = c + 26;

                }

                c = c - (key % 26);

            } else if (Character.isLowerCase(c)) {

                if(c < 'c')
                {

                    c = c + 26;

                }

                c = c - (key % 26);

            }

            encrypted += (char) c;

        }

        return encrypted;
    }
}

Input
XLMW MW MRHCFSC. M EQ LIVIFC SVHIVMRK XLEX EPP QC QIR QYWX IEX TITTIVSRM TMDDEW IZIVCHEC. XLMW SVHIV AMPP FI VITIEPIH SRPC YTSR QC VIXMVIQIRX. PSRK PMZI XLI GLMTQYROW!
Output
THIS IS IND?BO?. I AM HEREB? ORDERING THAT ALL M? MEN MUST EAT PEPPERONI PI@@AS EVER?DA?. THIS ORDER WILL BE REPEALED ONL? UPON M? RETIREMENT. LONG LIVE THE CHIPMUNKS!

Why did not output
THIS IS INDYBOY. I AM HEREBY ORDERING THAT ALL MY MEN MUST EAT PEPPERONI PIZZAS EVERYDAY. THIS ORDER WILL BE REPEALED ONLY UPON MY RETIREMENT. LONG LIVE THE CHIPMUNKS!
I miss What??
Please Tell me

This is not the same code you had at your previous thread. Why did you changed it?

Also why are you checking this:
if(c < 'C')
BEFORE you call this:
c = c - (key % 26)

Also why are you using this character: 'C'. I already explained what you should put there

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.