- 1
How to remove zero from a number
a simple java program to remove all the zeroes from a given number
3 odpowiedzi
+ 8
From the perspective of a C++ programmer, I'd take input as string and transfer all characters which are not '0' over to another character array, in which I will then convert to another string.
+ 7
@Justin Hill no need to undermine your own efforts. The method is direct and splendid.
+ 2
Might not be the best way, but it's what I came up with. Basically I wrote a method that turned the Integer into a string, removed the parts of the string I didn't want, turned it back into an integer, and returned it. felt like a dirty way to do it, but it worked
public static int remove(int x){
String var = String.valueOf(x);
var = var.replace("0", "");
x = Integer.valueOf(var);
return x;
}
int number = 1305603020;
number = remove(number);
System.out.println(number);
System.out.println(remove(1010101));