Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have implemented it in a different way, but it works as you expect, only for uppercase as in your example:</p> <pre><code>import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.List; public class WhileLoopIssue { public static void main( String[] args ) throws IOException { BufferedReader myInput = new BufferedReader( new InputStreamReader( System.in ) );// Buffered Reader reads the // number inputed final List&lt;String&gt; letterList = Arrays.asList( "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( "Enter a phrase: " ); String phrase = myInput.readLine(); final String[] letters = phrase.split( "" ); // Split input phrase final StringBuffer buffer = new StringBuffer(); // Variable to save letters. Could be a String as well. for ( int i = 0; i &lt; letters.length; i++ ) { final int letterIndex = letterList.indexOf( letters[i] ); // Get the numeric value of the letter if ( letterIndex &lt; 0 ) // Skip iteration if not found. Maybe a lowercase, or an empty String continue; final int nextLetterIndex = 13 + letterIndex; // Actual value of the letter + 13 if ( nextLetterIndex &gt; letterList.size() ) { buffer.append( nextLetterIndex % letterList.size() ); // Actual value greater than the total number of letters in the alphabet, so we get the modulus for the letter } else { buffer.append( letterList.get( nextLetterIndex ) ); // Letter in the range, get it } } System.out.println( buffer.toString() ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload