Computer Science, asked by Elle098, 10 hours ago

Write a program to input a three digit number. Find the difference between the product and the sum of the first and last digit.

Answers

Answered by anindyaadhikari13
11

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

The given problem is solved using language - Java.

import java.util.Scanner;  // Importing scanner class

public class Main{  // start of class

   public static void main(String args[]){   // start of main()

       Scanner sc=new Scanner(System.in);  // object of scanner class created

       int n,f,l,v;  // required variables are declared

       System.out.print("Enter a three digit number: ");  // asks the user to enter a number

       n=sc.nextInt(); // accepts the number

       f=n/100;   // extracts the first digit of the number

       l=n%10;  // extracts the last digit of the number

       v=f‎*‎l-(f+l);   // calculate the difference between the product and sum of first and last digit

       System.out.println("Result: "+v);  // Display the value

       sc.close();  // close the scanner class

   }  // main() closed

}  // class closed

I have added comments on every line so that you can understand the co‎de very well.

See the attachment for output.

Attachments:
Similar questions