Computer Science, asked by arpitkesari, 6 months ago

Write a program to accept four number and check the number palindrome or not. If it is palindrome then display the sum of last two digits else display the product of first two digits of the original number.

please give answer​

Answers

Answered by khushi7190
0

Answer:

If a number remains same, even if we reverse its digits then the number is known as palindrome number. For example 12321 is a palindrome number because it remains same if we reverse its digits. In this article we have shared two C programs to check if the input number is palindrome or not. 1) using while loop 2) using recursion.

Answered by udayagrawal49
0

Answer: The required java program is :-

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    System.out.print("Enter a four digit number : ");

    String num = scan.next();

    scan.close();

    int num1 = Integer.parseInt(num);

    int digit;

    StringBuffer numD = (new StringBuffer(num)).reverse();

    if(num.equals(numD.toString())) {

        int result = 0;

        digit = num1%10;

        result += digit;

        num1 /= 10;

        digit = num1%10;

        result += digit;

        System.out.println("\nThe given number is a palindrome. Sum of last two digits is "+result);

    }

    else {

        int result = 1;

        num1 /= 100;

        digit = num1%10;

        result *= digit;

        num1 /= 10;

        result *= num1;

        System.out.println("\nThe given number is not a palindrome. Product of first two digits of original number is "+result);

    }

   }

}

Please mark it as Brainliest.

Similar questions