Write a java program to find first digit,last digit and sum of given number ?

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ต.ค. 2024

ความคิดเห็น • 24

  • @rohanraj9067
    @rohanraj9067 3 ปีที่แล้ว +4

    If the input is 001, its returning 1 as first digit and 1 as last digit due to which the sum of first and last digit is equals 2
    that is practically totally wrong, so please suggest us what to do in order to solve this problem.

  • @Abdulrahman-my3tu
    @Abdulrahman-my3tu 4 ปีที่แล้ว +2

    I appreciate your help

  • @sheenvarghese1420
    @sheenvarghese1420 3 ปีที่แล้ว +1

    Thank you sir for such great explanation

  • @rohitmore7725
    @rohitmore7725 3 ปีที่แล้ว +1

    convet to string reverse the number and then % by 10 you get the first digit(if there is no restriction to use java inbuilt methods)

  • @travel_n_music
    @travel_n_music 4 ปีที่แล้ว +4

    Excellent work sir❤️

    • @springhibernatetutes
      @springhibernatetutes  4 ปีที่แล้ว

      Thanks for your valuable comment.There are many videos in description you can watch and share your feedback

  • @itspossible5920
    @itspossible5920 4 ปีที่แล้ว +2

    Thanks Sir, Wonderful job, is it possible for you to paste the coding in comment

  • @RakibHasan-455
    @RakibHasan-455 2 ปีที่แล้ว +1

    int firstDigit = 0, lastDigit = num % 10;
    while (num > 0) {
    int digit = num % 10;
    num = num / 10;
    firstDigit = digit;
    sum = sum + digit;
    }

  • @srivarshinis9351
    @srivarshinis9351 ปีที่แล้ว

    thnkyou sir

  • @swarnalibhattacharjee3659
    @swarnalibhattacharjee3659 4 ปีที่แล้ว

    for OOPS concept it could be much easier .. like that..........
    import java.util.*;
    public class SumOfFirstLast {
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int num = sc.nextInt();
    int S=0;
    int[] digits = Integer.toString(num).chars().map(c -> c-'0').toArray();
    for(int i=0;i

  • @rajanunia4265
    @rajanunia4265 ปีที่แล้ว

    Sir mujhe first price last digit number how calcutta at hindi version

  • @gopaljaiswal1876
    @gopaljaiswal1876 3 ปีที่แล้ว

    Sir if the num ==100
    Then we use
    Firstdigit=num
    While(Firstdigit>=10)
    {Firstdigit=Firstdigit/10}
    return Firstdigit
    Thn sir our output will be 10
    So sir i think we use while(Firstdigit>=9)

    • @sumitvelaskar
      @sumitvelaskar 3 ปีที่แล้ว

      it's greater than or equal to, the condition will be true if the number is 10

  • @pradeepamatya6092
    @pradeepamatya6092 4 ปีที่แล้ว +1

    so nice

  • @47lokeshkumar74
    @47lokeshkumar74 ปีที่แล้ว

    Nice

  • @debasispadhi4426
    @debasispadhi4426 4 ปีที่แล้ว

    sir in this way can i do?
    import java.util.*;
    public class Code1 {

    public static void main(String[] args) {


    Scanner sc=new Scanner(System.in);
    int num=sc.nextInt();
    int LastDigit=num%10;
    int FirstDigit=num;
    int s=0;
    int r;
    //int p;
    while(FirstDigit>=10)
    {

    FirstDigit=FirstDigit/10;
    }
    System.out.println("the last digit is->"+LastDigit);
    System.out.println("the ist digit->"+FirstDigit);
    int sum=FirstDigit+LastDigit;
    if(sum>=10)
    {

    while(sum!=0)
    {
    r=sum%10;
    s=s+r;
    sum=sum/10;
    }
    System.out.println("the sum is->"+s);
    }
    else
    {
    System.out.println("Sum is->"+ sum);
    }



    }

    }

  • @idan7bitton
    @idan7bitton 3 ปีที่แล้ว +1

    T U V M !!! you helped me alot.

  • @rajeshc1305
    @rajeshc1305 4 ปีที่แล้ว

    Nice