Juxtapose number in Int [duplicate] - java

This question already has answers here:
How to concatenate int values in java?
(22 answers)
Closed 7 years ago.
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 ?

Concatenate two numbers as a String and parse that String back to int.
EPSGCode = Integer.parseInt(""+coordinateReferenceSystem+fuseauUTM_1);

Related

Java casting in wrapper Number classes [duplicate]

This question already has answers here:
Java: Why can't I cast int to Long
(3 answers)
Wrapper classes - why integer literals fail for Long but work for anything smaller
(2 answers)
Closed 1 year ago.
Why it's correct:
Long l = new Long(10);
but it's not correct:
Long l2 = 10;
I understand that int is substituted here, but why is new Long(10) correct?

Getting Integers from Char Array? [duplicate]

This question already has answers here:
How can I convert a char to int in Java? [duplicate]
(4 answers)
Java: parse int value from a char
(9 answers)
Closed 3 years ago.
I was experimenting with char arrays and integers, when I found something that confused me a lot. In Java, if you type the following code:
String inputs = "123";
char[] inputs2 = inputs.toCharArray(); // Turn String into Char Array
int a = inputs2[0];
println(a);
I would have expected for "a" to return 1 because 1 is the first element in the array. However, it returned 49. Why does this occur? Is there any way to get around this issue?

Java - method that returns lowest integer from parameter [duplicate]

This question already has answers here:
How do I get the max and min values from a set of numbers entered?
(8 answers)
Closed 6 years ago.
I have a method that takes 4 integers/numbers as a parameter, and I want the method to return the lowest number from the parameter. How do I do this?
public int example (int tall1, int tall2, int tall3, int tall4) {
int lowest = Math.min(tall1,tall2);
int lowest1 = Math.min(tall3, tall4);
int lowest2 = Math.min(lowest,lowest1);
return lowest2;
}
This worked!

Convert a string value into an int [duplicate]

This question already has answers here:
How do I convert a String to an int in Java?
(47 answers)
How to do an Integer.parseInt() for a decimal number?
(10 answers)
Closed 9 years ago.
How to convert string value into int? I am getting number format exception.
String s = "20.00";
int i = (Integer.parseInt(s));
System.out.println(i);
Result should be like i=20.
What about:
int i = (int) Double.parseDouble(s);
Of course, "20.00" is not in a valid integer format.
String s = "20.00";
is not valid Integer value that is the reason its throwing NumberFormatException.
Format your number using either Double or Float then using narrow casting cast you number to int but you may loose precision if exists.
i.e. int I = (int) Double.parseDouble(str);

i++ still working for immutable Integer in Java? [duplicate]

This question already has answers here:
Is Integer Immutable
(12 answers)
Closed 9 years ago.
I know Integer is immutable in Java. But I tried this:
Integer i = 4;
i++;
System.out.println(i); // output is 5
Why the self-increment is still working? Did Java create a new Integer object?
i++;
is equivalent to:
i = i + 1;
which i now refers to a different Integer object (5).

Categories

Resources