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.
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
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)
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) {
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.
I appreciate your help
Thank you sir for such great explanation
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)
Excellent work sir❤️
Thanks for your valuable comment.There are many videos in description you can watch and share your feedback
Thanks Sir, Wonderful job, is it possible for you to paste the coding in comment
You can join my telegram group .iam pasting my code there
Join Telegram group : t.me/learnwithkrishnasandeep
int firstDigit = 0, lastDigit = num % 10;
while (num > 0) {
int digit = num % 10;
num = num / 10;
firstDigit = digit;
sum = sum + digit;
}
thnkyou sir
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
Sir mujhe first price last digit number how calcutta at hindi version
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)
it's greater than or equal to, the condition will be true if the number is 10
so nice
Nice
Thanks
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);
}
}
}
T U V M !!! you helped me alot.
Nice