Computer Science, asked by singhmansi0152, 2 months ago

WAP to enter a number to display the last digit of the number in java​

Answers

Answered by anindyaadhikari13
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:

  1. START.
  2. Accept the number.
  3. Divide the number by 10 and obtain the remainder.
  4. Display the remainder.
  5. STOP.

See the attachment for output ☑.

Attachments:
Similar questions