Write a program to initialize fractional numbers 7.5, 3.2, 6.4. print the sum and product of the numbers.
(Java)
Answers
Answer:
Hope you like the code !!!
Explanation:
import java.util.Scanner;
class Function
{
double a= 7.5;
double b= 3.2;
double c = 6.4;
void add()
{
double d = a+b+c;
System.out.println("The sum of numbers is : "+d);
}
void product()
{
double e = a*b*c;
System.out.println("The product of the numbers is "+e);
}
}
public class Main
{
public static void main (String [] args)
{
Scanner sc = new Scanner(System.in);
int val,f;
Function f1 = new Function();
System.out.println("Press 1 for 'Sum' & 2 for 'Product'");
val = sc.nextInt();
if (val==1)
f1.add();
else if(val==2)
f1.product();
}
}
Hey there!
The program is as follows:
class Fractionalno
{
public static void main(String args[])
{
doube a,b,c=0;
a = 7.5;
b = 3.2;
c = 6.4;
double s = a + b + c;
double p = a*b*c;
System.out.println("Sum =" + s);
System.out.println("product =" + p);
}
}
Sample Output:
Sum = 17.1
Product = 153.6