Reverse the given number simple Java programming Code by Naymul Islam PCIU CSE 18

 import java.util.Scanner;


public class ReverseTheGivennNumber {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();


        int rev = 0;

        while (num > 0) {

            int lastDigit = num % 10;

            rev = (rev * 10) + lastDigit;

            num /= 10;

        }

        System.out.println(rev);

    }

}


import java.util.Scanner;

public class ReverseTheGivennNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();

        int rev = 0;
        while (num > 0) {
            int lastDigit = num % 10;
            rev = (rev * 10) + lastDigit;
            num /= 10;
        }
        System.out.println(rev);
    }
}

No comments:

Post a Comment

Max Sub Array Sum: Kadane's Algorithm

Code of: Max Sub Array Sum: Kadane's Algorithm. public class MaxSubArraySumKadanesALgorithm {     public static void Kadane ( int ...