Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,25 @@
public class VariableDeclarationReset {
public static void main(String[] args) {
int[] s = {1, 2, 2, 3, 4, 4, 5};
// There is no output as 'prev' is created anew each time
// around the loop and set to zero.
for (int i = 0; i < s.length; ++i) {
int curr = s[i];
int prev = 0;
// int prev; // triggers "error: variable prev might not have been initialized"
if (i > 0 && curr == prev) System.out.println(i);
prev = curr;
}
int gprev = 0;
// Now 'gprev' is used and reassigned
// each time around the loop producing the desired output.
for (int i = 0; i < s.length; ++i) {
int curr = s[i];
if (i > 0 && curr == gprev) System.out.println(i);
gprev = curr;
}
}
}