Google+

Friday, December 27, 2013

Program to Rotate a Number using JAVA

Java a platform independent programming language.In this program you can rotate the number using Java.

EXAMPLE :
Original number:54321
Rotated Number :15432

PROGRAM :
import java.util.Scanner;
/**
 * @author Arun
 */
public class rotatetest {
    public static void main(String args[])
    {
        Scanner scn = new Scanner(System.in);
        System.out.println("Enter the Number to rotate");
        int number = scn.nextInt();
        int length = (int)(Math.log10(number)+1);       
        int rotate = number%10;
        rotate = rotate * (int) Math.pow(10, length-1);
        number = number/10;
        rotate = rotate + number;
        System.out.println("Rotated numb is "+rotate);
    }
}
Don't forget to give your valuable comments.

No comments:

Post a Comment