java - Creating a cipher, but returning error -


i trying make cipher, in type word, , gets shifted whatever user chooses, getting error:

exception in thread "main" java.lang.stringindexoutofboundsexception: string index out of range: 2
@ java.lang.string.charat(unknown source)
@ cipher.mycipher.main(mycipher.java:24)

i not sure why getting error?

here code:

public class mycipher {      public static void main(string[] args) {         int[] storagelocation = new int[25];         char[] letter1 = new char[25];         char[] init = new char[25];         scanner consolereader = new scanner(system.in);         char[] letters = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',             'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};         system.out.println("what word cipher?");         string original = consolereader.nextline();         system.out.println("how shift by");         int shift = consolereader.nextint();          (int = 0; < 25; i++) {             storagelocation[i] = i;             letter1[i] = letters[i];             if (letter1[i] == (original.charat(i))) {                 letter1[i] = init[i];             }         }         system.out.println(arrays.tostring(init));     } } 

you must add condition

 (int i= 0; < original.length(); i++) {             storagelocation[i] = i;             letter1[i] = letters[i];             if (letter1[i] == original.charat(i)) {                 letter1[i] = init[i];             }  } 

do not excede lenght of original else loop iterate until 25.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -