0

I'm a beginner in Java. I have a simple question :

int EPSGcode = 0;
int coordinateReferenceSystem = 326;
int fuseauUTM_l = 30;

I would like to juxtapose "coordinateReferenceSystem" and "fuseauUTM_l" in ESPGcode.

I get EPSGcode = 356, but I want EPSGcode = 32630... Simple question, any ideas ?

  • @ChristopherWirt That post doesn't help me at all !!! – Capricia Six Jun 24 '15 at 13:29
  • 1
    It's an almost identical question, but as a beginner, I can see the confusion. The most upvoted answer on that thread (not in the first few, very confusing) is almost identical to the answer you want to accept. The only difference is that you're left with a string in those. How do you solve that? Well, in Java, most of the basic data types like Integer and Double have a parse method. So `Integer.parseInt("523")` will return the INTEGER 523, even though it was a string before. Sorry to sound condescending, I don't mean to. – Christopher Wirt Jun 24 '15 at 13:35

1 Answers1

1

Concatenate two numbers as a String and parse that String back to int.

EPSGCode  = Integer.parseInt(""+coordinateReferenceSystem+fuseauUTM_1);
zubergu
  • 3,646
  • 3
  • 25
  • 38
  • Yes, It works well, I will accept your answer, thank you ! – Capricia Six Jun 24 '15 at 13:17
  • @CapriciaSix One trap to avoid as a beginner is to make sure you understand code snippets when you're using them, it's how you become a better programmer :) – Christopher Wirt Jun 24 '15 at 13:36
  • 1
    @ChristopherWirt So I have one question, I don't understand why it dosen't work if I delete the ""+ in "parseInt(""+coordinateReferenceSystem+fuseauUTM_1);" – Capricia Six Jun 24 '15 at 13:39
  • @CapriciaSix The reason for that, is that Java doesn't know you want it to be a String unless you do "String concatanation". The full, clear answer would be to have `""+coordinateReferenceSystem+""+fuseauUTM_1`. It's sort of confusing, for sure, but if you just do `someInt+anotherInt` that's kind of like doing `5+5`, but when you do `""+someInt`, that makes someInt a string, and adds it to the end of the `""` string (which is empty). THEN, when you add the OTHER int, since you're adding it to a string (the one from `""+someInt` since that's a string now) IT is added to the end of the string. – Christopher Wirt Jun 24 '15 at 13:42
  • 1
    @ChristopherWirt Thank you very good explanation I understood better !! – Capricia Six Jun 24 '15 at 13:50