WAP to enter a number to display the last digit of the number in java
Answers
Answered by
3
Required Answer:-
Question:
- Write a program in Java to enter a number and display the last digit of the number.
Solution:
Here comes the program.
import java.util.*;
public class LastDigit {
public static void main(String[] args) {
int n, d;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
n=sc.nextInt();
d=n%10;
System.out.println("Last digit of: "+n+" is: "+d);
sc.close();
}
}
Algorithm:
- START.
- Accept the number.
- Divide the number by 10 and obtain the remainder.
- Display the remainder.
- STOP.
See the attachment for output ☑.
Attachments:


Similar questions