// Java program to swap first & Last digit of a number example-5643, output-3645
import java.util.Scanner;
class SwapFirstAndLastDigit
{
public static void main(String args[])
{
int n,f,l,r=0,tmp,swap,c,d;
Scanner s=new Scanner(System.in);
System.out.println("Enter the number:\n");
n=s.nextInt();
tmp=n;
l=n%10;
while(n>10)
{
n=n/10;
}
f=n;
n=tmp/10;
while(n>10)
{
c=n%10;
r=r*10+c;
n=n/10;
}
swap=l;
while(r>0)
{
d=r%10;
swap=swap*10+d;
r=r/10;
}
swap=swap*10+f;
System.out.println("After swap:"+swap);
}
}
import java.util.Scanner;
class SwapFirstAndLastDigit
{
public static void main(String args[])
{
int n,f,l,r=0,tmp,swap,c,d;
Scanner s=new Scanner(System.in);
System.out.println("Enter the number:\n");
n=s.nextInt();
tmp=n;
l=n%10;
while(n>10)
{
n=n/10;
}
f=n;
n=tmp/10;
while(n>10)
{
c=n%10;
r=r*10+c;
n=n/10;
}
swap=l;
while(r>0)
{
d=r%10;
swap=swap*10+d;
r=r/10;
}
swap=swap*10+f;
System.out.println("After swap:"+swap);
}
}
1 Comments
Bro swapping first and third how
ReplyDelete