Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In java please, Write a program called CaesarLite that encodes a message using a

ID: 3717938 • Letter: I

Question

In java please,

Write a program called CaesarLite that encodes a message using a Caesar cipher (https://en.wikipedia.org/wiki/Caesar cipher). The user should be prompted for the number of positions to shift (positive or negative) and a message to encode. For example, a shift of 3 would map A to D and B to E. You can assume that only capital letters need to be shifted and that other characters will not be changed. For this version, you can assume that the shift never of the alphabet. Example 1: Enter shift: 4 Enter message: HELLO Encoded message: LIPPS Example 2: Enter shift: -1 Enter message: IBM 9000 Encoded message: HAL 9000

Explanation / Answer

CaesarLite.java

import java.util.Scanner;

public class CaesarLite {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter shift:");

int n = scan.nextInt();

scan.nextLine();

System.out.println("Enter message:");

String s = scan.nextLine();

System.out.println("Encoded message:");

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

if(Character.isAlphabetic(s.charAt(i))) {

System.out.print((char)(s.charAt(i)+n));

} else {

System.out.print(s.charAt(i));

}

}

System.out.println();

}

}

Output:

Enter shift:
-1
Enter message:
IBM 9000
Encoded message:
HAL 9000

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote