Write A java program to show that ,a special two digit number is such that when the sum of its digit is added to the product of its digit. The result is equal to the original number. (e.g. 5+9 = 14, 5*9= 45,then sum = 45+14= 5 9).
Answers
Answer:
class special
{
public static void main(int n)
{
int k,j=0,m=n,b=1;
while (m!=0)
{
k=m%10;
j=j+k;
b=b*k;
m=m/10;
}
if((k+b)==n)
System.out,println("Special number");
else
System.out,println("Not a Special number");
}
}
Explanation:
Answer:
import java.util.Scanner;
public class Specialtwodigit
{
public static void main()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a: ");
int a = in.nextInt();
System.out.print("Enter b: ");
int b = in.nextInt();
System.out.print("Enter c: ");
int c = in.nextInt();
double d = Math.pow(b, 2) - (4 * a * c);
// double d =(b*b) - (4 * a * c);
if (d >= 0) {
System.out.println("Roots are real.");
double r1 = (-b + Math.sqrt(d)) / (2 * a);
double r2 = (-b - Math.sqrt(d)) / (2 * a);
System.out.println("Roots of the equation are:");
System.out.println("r1=" + r1 + ", r2=" + r2);
}
else
{
System.out.println("Roots are imaginary.");
}
}
}
Hope it helps!!