Computer Science, asked by Ajit1pandey, 1 year ago

Questions 13 solutions in java

Attachments:

Answers

Answered by Rajdeep11111
1
Heya friend!!
Rajdeep here....

Any problem regarding JAVA programs?
Just ask me!!

Your answer:

import java.util.Scanner;
class Digit
{
public int lastdigit(int num)
{
int n;
n = num%10;             //The last digit gets stored in variable n.
return (n);
}
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
Digit obj = new Digit();
int x;
System.out.print("Enter the number whose last digit is to be printed: ");
x = sc.nextInt();
int result = obj.lastdigit(x);
System.out.println("The last digit of the number is: " + result);
}
}

In the above program, I have used a Scanner class to accept the number from the user. You can also use BufferedReader or simple Parameter input method.
Thanks!!

Ajit1pandey: thanku
Rajdeep11111: You are most welcome
Similar questions