Computer Science, asked by gangotri13, 6 months ago

Write a basic program to input a 3-digit number and find the reverse of the number, then find the sum difference and product of that two numbers,​

Answers

Answered by Oreki
1

import java.util.Scanner;

public class Numbers {

static int reverse(int number) {

return Integer.parseInt(new StringBuffer(number + "").reverse( ).toString( ));

}

public static void main(String[ ] args) {

System.out.print("Enter number - ");

int number = new Scanner(System.in).nextInt( ), reversedNumber = reverse(number);

System.out.printf("%nSum - %d%nDifference - %d%nProduct - %d", number + reversedNumber,

number - reversedNumber,

number * reversedNumber);

}

}

Answered by anindyaadhikari13
2

Question:-

Write a program to input a three digit number and find the reverse of the number, then find the sum difference and product of that two numbers.

Program:-

import java.util.*;

class Number

{

public static void main(String s[])

{

Scanner sc = new Scanner(System.in);

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

int n=sc.nextInt();

int n1=n, s=0;

while(n!=0)

{

s=s*10+n%10;

n/=10;

}

n=n1;

System.out.println("Reversed: "+s);

System.out.println("Sum: "+(s+n));

System.out.println("Difference: "+(s-n));

System.out.println("Product: "+s*n);

}

}

Similar questions