Showing posts with label sum-of-first-and-last-digit-of-a-number. Show all posts
Showing posts with label sum-of-first-and-last-digit-of-a-number. Show all posts

Wednesday, July 8, 2020

Write a program to input a number and find the sum of First and Last digit of this number?(2784=2+4=6first and last digit sum)

45)  Write a program to input a number and find the sum of First and Last digit of this number?(2784=2+4=6first and last digit sum)


import java.util.*;
public class First_last_digit_sum
{
   public static void main(String args[ ])
   {
      Scanner sc = new Scanner (System.in);
      System.out.println("Enter a number");
      int a = sc.nextInt();
      int p =a;
      int c = 0;
      while(p>0)
      {
          p=p/10;
          c++;
      }
      int x = (int)Math.pow(10,(c-1));
      int l = a/x;
      int f = a%10;
      int s = l+f;
      System.out.println("SUM of FIRST and LAST digit of a entered number = "+s);
    }
}

Output :  

sum-of-first-and-last-digit-of-a-number


Write a program to input a number and find the Sum and Count the all digit of this number.(2784=2+7+8+4=21…no. of digit=4)


 jhvghvgk ;nkjn ,nkjhj