I've the below Java code.
public class Test {
public static void main(String[] args) {
int i = 5;
int j = 0;
for (int k = 1; k <= i; k++) {
System.out.println("row count is " + j);
increment(j);
j += 1;
}
}
private static int increment(int j) {
if (j == 2) {
j += 1;
System.out.println("row count is " + j);
}
return j;
}
}
Here I want to increment the j
value based on the return value.
The current output I'm getting is.
row count is 0
row count is 1
row count is 2
row count is 3
row count is 3
row count is 4
My expected output is
row count is 0
row count is 1
row count is 2
row count is 3
row count is 4
row count is 5
Here I'm aware that putting
if (j == 2) {
j += 1;
System.out.println("row count is " + j);
}
in my for
block solves the problem, but this is a like a replica of my main code which in in the form of my input provided. And I've to follow this pattern, i mean increment the value by checking for the condition in my method.
please let me know how can i get this.
Thanks