Note that there are some explanatory texts on larger screens.

plurals
  1. POencoding gives two different output?
    primarykey
    data
    text
    <p>There is two classes:</p> <p>key.java and test.java</p> <p>in the test.java the expected outcome is ascii value of a + 5 = f? which does get outputted but when i run it the line:</p> <pre><code>System.out.println(k1.encode('G')); // expected output 'L' </code></pre> <p>outputs not the ascii value of G plus 5, it outputs: lower case e?</p> <p>i am getting to the end of my threshold here, why?</p> <p>key.java:</p> <pre><code>class Key{ private int value; Key(int value){ this.value = value; } public char encode(char c){ if (isValidKey(value) == true) { if (c &gt;= 'a' &amp;&amp; c &lt;= 'z'){ c = (char)(( c - 'a' + value) % 26 + 'a'); }else if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z'){ c = (char)(( c - 'A' + value) % 26 + 'A'); }else if (c &gt;= '0' &amp;&amp; c &lt;= '9'){ c = (char)(( c - '0' + value) % 10 + '10'); } else { return '.'; } return c; } public char decode(char c){ if (isValidKey(value) == true) { if (c &gt;= 'a' &amp;&amp; c &lt;= 'z'){ c = (char)(( c - 'a' - value) % 26 + 'a'); }else if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z'){ c = (char)(( c - 'A' - value) % 26 + 'A'); }else if (c &gt;= '0' &amp;&amp; c &lt;= '9'){ c = (char)(( c - '0' - value) % 10 + '10'); }else{ return'.'; } return c; } public static boolean isValidKey(int value){ if (value &gt;= 0 &amp;&amp; value &lt;= 25){ return true; } else { return false; } } } } } </code></pre> <p><strong>test.java:</strong></p> <pre><code>public class Test{ public static void main(String[] args) { Key k1,k2; k1=new Key(5); k2=new Key(15); String s="This is a test. Let's see if that works"; String t=Cryptic.encrypt(s,k1); System.out.println("Original: "+s); System.out.println("Encoded with k1: "+t); System.out.println("The result ddecoded with k1: "+Cryptic.decrypt(t,k1)); //individual tests System.out.println(Key.isValidKey(5)); // the expected output is true System.out.println(Key.isValidKey(25)); // the expected output is true System.out.println(Key.isValidKey(-1)); // the expected output is false System.out.println(Key.isValidKey(-10)); // the expected output is false System.out.println(Key.isValidKey(200)); // the expected output is false System.out.println(Key.isValidKey(1)); // the expected output is true Key k3= new Key(-1); System.out.println(k1.encode('a')); // expected output 'f' System.out.println(k2.encode('a')); // expected output 'p' System.out.println(k1.encode('7')); // expected output '2' System.out.println(k3.encode('a')); // expected output '.' System.out.println(k3.encode('7')); // expected output '.' System.out.println(k1.decode('a')); // expected output 'v' System.out.println(k2.decode('a')); // expected output 'l' System.out.println(k1.decode('7')); // expected output '2' System.out.println(k3.decode('a')); // expected output '.' System.out.println(k3.decode('7')); // expected output '.' System.out.println(k1.encode('G')); // expected output 'L' System.out.println(k1.decode('G')); // expected output 'B' System.out.println(k1.encode('*')); // expected output '*' } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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