-
Notifications
You must be signed in to change notification settings - Fork 0
/
SumOfFirstAndLast.java
39 lines (31 loc) · 1.09 KB
/
SumOfFirstAndLast.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.codewithmanish;
public class SumOfFirstAndLast {
public static void main(String args[] ) {
int value=sumFirstAndLastDigit(10);
System.out.println("THE SUM IS "+value);
// write your code here
}
public static int sumFirstAndLastDigit(int number){
if(number<0){
return -1;
}
else{
if(number<=9){
System.out.print(2*number);
return 2*number;
}else{
int last=number%10;
System.out.println("LAST DIGIT IS"+last);
int temp=number;
System.out.print("TEMP BEFORE GOING TO LOOP IS "+temp);
while(temp>=10){
temp=temp/10;
System.out.println("TEMP INSIDE LOOP IS"+temp);
}
System.out.println("TEMP OUTSIDE LOOP IS"+temp);
System.out.println("SUM IS "+(temp+last));
return (temp+last);
}
}
}
}