Caesar

import java.util.*; public class CaesarShift { public static void main(String[]args){ Scanner sc = new Scanner(System.in); int shift = 4; String en = " "; String a = ("abcdefghijklmnopqrstuvwxyz"); System.out.println("Enter any word:"); String in = sc.next(); int ln = in.length(); int count = 0; while(count<ln){ String temp = in.substring(count,count+1); int spot = a.indexOf(temp); int shiftedSpot = (spot + shift)%26; en += a.substring(shiftedSpot, shiftedSpot+1); count++; } System.out.println(en); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.