Caesar Salad

import java.util.*; public class CaesarSalad { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int shift = 4; String encrypt = ""; String alpha = "abcdefghijklmnopqrstuvwxyz"; System.out.println("Give me a word and forever shall this word be hidden amongst the shadows of the interwebs. "); String in = sc.next();//thing int ln = in.length(); int count = 0; while(count<ln){ String word = in.substring(count,count + 1); int index = alpha.indexOf(word); int shiftIndex = (index + shift)%26; encrypt += alpha.substring(shiftIndex, shiftIndex+1); count++; }//end of while //for (count = 0; count < ln; count++;) { // String word = in.substring(count, count + 1); //int index = alpha.indexOf(word); //int shiftIndex = (index + shift)%26; //encrypt += ln[count] + alpha.substring(shiftIndex, shiftIndex+1); //Array required somewhere here //} System.out.println(encrypt); }// end of main string }// end of clase CaesarSalad

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.