Note that there are some explanatory texts on larger screens.

plurals
  1. POMinimize code in reference to read/write operations
    primarykey
    data
    text
    <p>I started with the following code:</p> <pre><code>class Vereinfache2_edit { public static void main(String[] args) { int c1 = Integer.parseInt(args[0]); int c2 = Integer.parseInt(args[1]); int c3 = Integer.parseInt(args[2]); /* 1 */if (c2 - c1 == 0) { /* 2 */if (c1 != c3) { c3 += c1; /* 4 */System.out.println(c3); /* 5 */c3 *= c2; /* 6 */} } /* 7 */if (c1 == c3) /* 8 */if (c1 - c2 == 0) /* 9 */{ c3 += c1; /* 10 */System.out.println(c3); /* 11 */c3 *= c1; /* 12 */if (c1 &lt; c2) c2 += 7; /* 13 */else c2 += 5; /* 14 */} /* 15 */System.out.println(c1 + c2 + c3); } } // end of class Vereinfache2 </code></pre> <p>...and I ended with:</p> <pre><code>class Vereinfache2 { public static void main(String [] args) { int c1 = Integer.parseInt(args[0]) ; int c2 = Integer.parseInt(args[1]) ; int c3 = Integer.parseInt(args[2]) ; /* 1 */ /* 2 */ if (c2 == c1 &amp;&amp; c1 != c3){ /* 4 */ System.out.println(c3 += c2) ; /* 5 */ c3 = c3 * c2 ; /* 6 */ } /* 7 */ /* 8 */ if ( c2 == c1 &amp;&amp; c1 == c3){ /* 10 */ System.out.println(c3 *= 2) ; /* 11 */ c3 = c3 * c2 ; c2 = c2 + 5 ; /* 14 */ } /* 15 */ System.out.println( c1+c2+c3) ; } } // end of class Vereinfache2 </code></pre> <p>Do you see anything else like dead or switchable code?</p> <p>Thanks for all answers. I ended up with this working version:</p> <pre><code>class Vereinfache2 { public static void main(String [] args) { int c1 = Integer.parseInt(args[0]) ; int c2 = Integer.parseInt(args[1]) ; int c3 = Integer.parseInt(args[2]) ; /* 1 */ if(c2 == c1){ /* 2 */ if (c1 != c3){ c3 += c2; /* 4 */ System.out.println(c3) ; /* 6 */ }else{ c3 *= 2; /* 10 */ System.out.println(c3) ; /* 14 */ } c3 *= c2; c2 += 5; } /* 15 */ System.out.println(c1+c2+c3) ; } } // end of class Vereinfache2 </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.
 

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