Free Puzzle Questions with Answer using Java, C#, JavaScript and PHP

Java Quiz - Reverse Integer Number

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package reverseintegernumber;

/**
 *
 * @author Bereket
 */
public class ReverseIntegerNumber {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int sampleData = 12005;
        
        int result = reverseGivenInteger(sampleData);
        
        System.out.println(String.valueOf(result));
    }
    
    static int reverseGivenInteger(int givenInteger){
        int sign = 1;
        
        if(givenInteger == 0){
            return 0;
        }
        
        //check if given number is negative
        if (givenInteger < 0){
            sign = -1;
            givenInteger = (-1) * givenInteger; //change given negative number to posititve
        }
        
        int output = 0;
        while(givenInteger != 0){
            output = (output * 10) + (givenInteger % 10);
            givenInteger = givenInteger / 10;
        }
        
        return sign * output;//change proper sign to the out put and return result
    }
    
}