c++: #include <iostream> #include <string> using namespace std; int main() { int a; cin >> a; if (a % 10 == 0) { a = a / 10; if (a % 10 == 0) cout << a / 10 << endl; else cout << a % 10 << a / 10 << endl; } else { cout << a % 10 << a / 10 % 10 << a / 100 << endl; } return 0; } Java: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String numberString = scanner.nextLine(); String[] numberStrings = numberString.split(""); boolean hasNumber = false; for (int i=(numberStrings.length-1); i>=0 ; i--) { String number = numberStrings[i]; if (!hasNumber) { if (Integer.parseInt(number) != 0) { hasNumber = true; System.out.print(number); } } else { System.out.print(number); } } scanner.close(); } }