Remove digits from a number in Java [closed]
How do I remove the first digit of an integer? My input is an integer (for example i = 123456789). I then want to remove the first digit, so that i equals 23456789. try this n = n % (int) Math.pow(10, (int) Math.log10(n)); Here is one way to do it: Convert it to String Take the substring without the first "digit" Convert it to int Code: public static void main(String[] args) { int x = 123456789; String x_str = Integer.toString(x); int new_x = Integer.parseInt(x_str.substring(1)); System.out.println(new_x); } Output: 23456789 Note: This can be done in one line with int x = 123456789; int new_x