-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain12.java
More file actions
30 lines (19 loc) · 736 Bytes
/
Main12.java
File metadata and controls
30 lines (19 loc) · 736 Bytes
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
package loopinjava;
import java.util.Scanner;
public class Main12 {
public static void main(String[] args) {
int n, number, firstDigit, lastDigit, sum;
Scanner input = new Scanner(System.in);
System.out.println("Find first and last digit of a number.\n");
System.out.print("Enter a number: ");
number = input.nextInt();
lastDigit = number % 10;
firstDigit = number;
while(firstDigit >= 10) {
firstDigit = firstDigit / 10;
}
sum = firstDigit + lastDigit;
System.out.println("First Digit: " + firstDigit + ", Last Digit: " + lastDigit);
System.out.println("Sum: " + sum);
}
}