-1
public int Gauss_Jordan(double[][] matrix, int numOfRows, int numOfCols) { for (int col_j = 0; col_j<numOfCols; col_j++) { row_i = nonzeros ++; System.out.println(row_i+" and "+nonzeros); } //return matrix; return 0; } 

up above in the method called "Gauss_Jordan", you can see a for loop where it iterates until a certain condition is met. (duh.. lol sorry).

so i set row_i = nonzeros++ but here's the thing, when I print out each iteration i get

  • 0 and 1,
  • 1 and 2,
  • 2 and 3

. I would expect the output to be:

  • 1 and 1,
  • 2 and 2,
  • 3 and 3.

How come this is not the case?

2

3 Answers 3

4

You'd need ++nonzeros instead of nonzeros++ to get what you expect.

Sign up to request clarification or add additional context in comments.

5 Comments

@HovercraftFullOfEels ... Pretty sure he was ..... what's the issue?
time to drink more coffee. that's the issue. sorry.
@HovercraftFullOfEels go back to the java tutorial .... ;-) docs.oracle.com/javase/tutorial/java/nutsandbolts/op1.html
@rolfl: my eyes weren't seeing things clearly. 1+ to bruno and sanbhat.
+1 from me on the coffee ;-)
4

Thats called post-increment;

When you say row_i = nonzeros ++;

first the row_i will get assigned with the value of nonzeros and the nonzero will get incremented.

try pre-increment

row_i = ++nonzeros; 

Comments

0

If pre-increment is not what you wanted. Check the initialization of nonzeros and change it into '1` for it to show up as you want. Your codes are functioning as they should.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.