Joe Vox Joe Vox - 1 month ago 17
Java Question

Integer.parseInt is not converting variable to int

Let's assume we're having the following snippet of code:

System.out.println("Matchup : " + sp[0] + " vs " + sp[1] + " Winner" +
Integer.parseInt(sp[2]) < 0 ? "" : "" );


IDE saying that I'm trying to compare string with integer.
Any ideas?

Answer

Change this snippet:

System.out.println("Matchup : " + sp[0] + " vs " + sp[1] + " Winner" +
          Integer.parseInt(sp[2]) < 0 ? "" : "" );

Convert that too:

System.out.println("Matchup : " + sp[0] + " vs " + sp[1] + " Winner" +
          ((Integer.parseInt(sp[2]) < 0) ? "" : "") );

I recommend enclosing the whole thing in one parenthesis, then your condition expression in another set.

Edit:

Im sorry, I didn't close off your condition expression correctly (embarrass)