Computer Science, asked by mahuamondal303, 1 month ago

write a program which will accept 3 digit number and display first and the last digit in java​

Answers

Answered by anindyaadhikari13
11

\textsf{\large{\underline{Solution}:}}

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);

   }

}

\textsf{\large{\underline{Logic}:}}

  1. At first, we will accept the number from the user.
  2. Then we will divide the number by 100. Integer division takes place and the first digit is obtained as quotient.
  3. Then we will calculate the remainder using modulus operator.
  4. At last, the first and last digit are displayed.

See the attachment for output.

Attachments:
Similar questions