Change project structure to a Maven Java project + Refactor (#2816)

This commit is contained in:
Aitor Fidalgo Sánchez
2021-11-12 07:59:36 +01:00
committed by GitHub
parent 8e533d2617
commit 9fb3364ccc
642 changed files with 26570 additions and 25488 deletions

View File

@@ -0,0 +1,30 @@
package com.thealgorithms.maths;
import java.util.Scanner;
import java.util.NoSuchElementException;
import java.lang.IllegalStateException;
public class ReverseNumber {
public static void main(String[] args) {
int number;
int reverse = 0;
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Enter a number:");
number = sc.nextInt();
} catch (NoSuchElementException | IllegalStateException e) {
System.out.println("ERROR: Invalid input");
return;
}
while (number != 0) {
int remainder = number % 10;
reverse = reverse * 10 + remainder;
number = number / 10;
}
System.out.println("The reverse of the given number is: " + reverse);
}
}