Commit 9135d9c5 authored by yazan.halloul's avatar yazan.halloul

handle error create data commit

parent 88771451
...@@ -7,7 +7,7 @@ import parallelCounters.*; ...@@ -7,7 +7,7 @@ import parallelCounters.*;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
int start = 0; int start = 0;
int finish = 10; int finish = -1;
int[] data = RangeArrayBuilder.create(start, finish); int[] data = RangeArrayBuilder.create(start, finish);
for (int d:data for (int d:data
) { ) {
......
...@@ -2,10 +2,14 @@ package data; ...@@ -2,10 +2,14 @@ package data;
public class RangeArrayBuilder { public class RangeArrayBuilder {
public static int[] create(int start, int finish) { public static int[] create(int start, int finish) {
int[] data = new int[finish - start + 1]; if(start > finish) System.out.println("Error!!: Finish value should be grater than Start value");
for (int i = start; i <= finish; i++) { else {
data[i - start] = i; int[] data = new int[finish - start + 1];
for (int i = start; i <= finish; i++) {
data[i - start] = i;
}
return data;
} }
return data; return new int[0];
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment