Java Program to sum first and last digit of a number

      No Comments on Java Program to sum first and last digit of a number
import java.util.*;
class scan
{
 public static void main(String arg[])
  {
    int x,y,z=0,sum;
   Scanner kb=new Scanner(System.in);
   System.out.println("Enter any number");
   x=kb.nextInt();
   y=x%10;
   
   while(x!=0)
    {
	 z=x%10;
	 x=x/10;
	}
	sum=y+z;
	System.out.println("Sum of First and Last digit is:- "+sum);
  }
}

OUTPUT:-

sum

Leave a Reply

Your email address will not be published. Required fields are marked *