Completato RunGenerator (P7.1 nuovo)

This commit is contained in:
Giacomo R. 2023-01-15 16:48:04 +01:00
parent 1edb9d2152
commit dc9098851c
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
public class RunGenerator {
public static void main(String[] args) {
int[] values = {1,2,2,2,3,4,4,5,5,5,6,6,7,7,7,7,7,8,9,0};
boolean inRun = false;
for(int i = 0; i < values.length; i++) {
if(inRun) {
if(values[i] != values[i-1]) {
System.out.print(")");
inRun = false;
if(i < values.length - 1 && values[i] == values[i+1]) {
System.out.print("(");
inRun = true;
}
}
} else {
if(i < values.length - 1 && values[i] == values[i+1]) {
System.out.print("(");
inRun = true;
}
}
System.out.print(values[i]);
}
if(inRun) System.out.print(")");
}
}