write a program which will accept 3 digit number and display first and the last digit in java
Answers
Answered by
11
The given problem is solved using language - Java.
import java.util.Scanner;
public class NumberOperation{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int a,f,l;
System.out.print("Enter a three digit number: ");
a=sc.nextInt();
sc.close();
f=a/100;
l=a%10;
System.out.println("First Digit: "+f);
System.out.println("Last Digit: "+l);
}
}
- At first, we will accept the number from the user.
- Then we will divide the number by 100. Integer division takes place and the first digit is obtained as quotient.
- Then we will calculate the remainder using modulus operator.
- At last, the first and last digit are displayed.
See the attachment for output.
Attachments:
Similar questions
English,
15 days ago
Hindi,
15 days ago
CBSE BOARD X,
1 month ago
Environmental Sciences,
1 month ago
Math,
9 months ago
English,
9 months ago