80) Write a program to input a number and
Swap the first and last digit of
this number?(2784===4782)
import java.util.*;public class Swap_first_last_digit{public static void main(String args[ ]){Scanner sc = new Scanner (System.in);System.out.println("Enter a number");int a = sc.nextInt();int k = a;int c = 0;while(k>0){k=k/10;c++;}int m = (int)Math.pow(10,c-1);int n = a%m;int t = a/m;int r = n%10;n=n/10;n=(n*10)+t;n=(r*m)+n;System.out.println("Number after SWAPING First and Last Digit = "+n);}}
No comments:
Post a Comment
if you have any doubts, Please let me know.
Your Truly
Shashank Porwal