Write ac program to find sum of first and last digit of any number
Answers
Answered by
2
import java.util.*
class Sample
{
public static void main(String args[ ])
{
Scanner obj= new Scanner (System.in);
int n,k,r=0,sum;
System.out.println("Enter a Number ");
n= obj.nextInt( );
k=n;
while (k!=0)
{
k=k %10;
r=( r*10)+k;
k=k/10;
}
sum= (n%10)+(r%10);
System. out.println(" Sum of the first and the last digit of a number"+sum);
}
}
class Sample
{
public static void main(String args[ ])
{
Scanner obj= new Scanner (System.in);
int n,k,r=0,sum;
System.out.println("Enter a Number ");
n= obj.nextInt( );
k=n;
while (k!=0)
{
k=k %10;
r=( r*10)+k;
k=k/10;
}
sum= (n%10)+(r%10);
System. out.println(" Sum of the first and the last digit of a number"+sum);
}
}
Similar questions