Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do what you want without using a switch, simply by writing that:</p> <pre><code>s1value = s1.charAt(0)-'a'; //returns 0 if s1value="a", 1 if s1value="b", etc. </code></pre> <p>What i don't completely understand is what do you mean with </p> <pre><code>(s1 || s2) </code></pre> <p>Do you want to do something like this?</p> <pre><code> int s1Value = 0; int s2Value = 0; String s1 = "g"; String s2 = "a"; char s1char = s1.charAt(0); char s2char = s2.charAt(0); int myChar = Math.max(s1char, s2char); s1Value = s2Value = myChar - 'a'; </code></pre> <p><strong>UPDATE</strong></p> <p>In comments, you wrote:</p> <p><em>s1="g" and s2="g" before entering the switch, then the only case that will evaluate to true is case "g" and so both s1Value and s2Value will become 6 and then exit the switch.</em></p> <p>So, i think you're saying that s1 and s2 are initialized with the same value, so:</p> <pre><code> int s1Value = 0; int s2Value = 0; String s1 = "g"; String s2 = "g"; char s1char = s1.charAt(0); s1Value = s2Value = s1char - 'a'; //s1Value = s2Value = 6 </code></pre> <p>This should do what you want</p> <p><strong>UPDATE 2</strong></p> <p><em>with s1="a" and s2="d" we consider case "a", with s1="c" and s2="b" we consider case "b"</em></p> <p>Try this:</p> <pre><code> int s1Value = 0; int s2Value = 0; String s1 = "g"; String s2 = "a"; char s1char = s1.charAt(0); char s2char = s2.charAt(0); int myChar = Math.min(s1char, s2char); s1Value = s2Value = myChar - 'a'; </code></pre> <p>It should do the trick, test it and let me know if it works</p>
    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. VO
      singulars
      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