Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Caesar Cipher Encoder. Made by Ryan D. 2018
- // (Currently only works with lower-case letters.)
- package visual;
- import java.util.*;
- public class Main {
- static int shiftFac = 0;
- static String message = "";
- static String out = "";
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter the amount to shift:");
- shiftFac = Integer.parseInt(sc.nextLine());
- System.out.println("Enter the String:");
- message = sc.nextLine();
- char[] cmessage = message.toCharArray();
- for (char c: cmessage) {
- if(c!=' '&&c!='?'&&c!='!'&&c!='.'&&c!=',') {
- char shiftc = (char)(c + shiftFac);
- if (shiftc >= 123) {
- shiftc = (char)(shiftc - 26);
- out += shiftc;
- } else {
- out += shiftc;
- }
- } else {
- out += c;
- }
- }
- System.out.println("New string: " + out);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement