Computer Science, asked by navucr7njr, 9 months ago

write a java program to find product of first and last digit of a number​

Answers

Answered by pathaksurbhi153
8

Answer:

This program allows the user to enter any number. Next, this Java program returns the First and Last Digit of the user entered value.

// Java Program to find First and Last Digit of a Number

import java.util.Scanner;

public class FirstandLastDigit1 {

private static Scanner sc;

public static void main(String[] args)

{

int number, first_digit, last_digit;

sc = new Scanner(System.in);

System.out.print(" Please Enter any Number that you wish : ");

number = sc.nextInt();

first_digit = number;

while(first_digit >= 10)

{

first_digit = first_digit / 10;

}

last_digit = number % 10;

System.out.println("\n The First Digit of a Given Number " + number + " = " + first_digit);

System.out.println("\n The Last Digit of a Given Number " + number + " = " + last_digit);

}

}

Similar questions