In the previous article we have discussed Java Program to Compute bc(b-c)+ca(c-a)+ab(a-b) where Value of a, b and c are Given
In this program we are going to see how to compute a(b2-c2)+b(c2-a2)+c(a2-b2) where value of a, b, and c are given by using Java Programming language.
Java Program to Compute a(b2-c2)+b(c2-a2)+c(a2-b2) where Value of a, b, and c are Given
The formula of a(b2-c2)+b(c2-a2)+c(a2-b2) is given below.
a(b2-c2)+b(c2-a2)+c(a2-b2) = (a-b)(b-c)(c-a)
Now we will convert this into a valid Java expression.
Let x= a(b2-c2)+b(c2-a2)+c(a2-b2)
=(a-b)(b-c)(c-a)
= (a-b)*(b-c)*(c-a)
Example:
Suppose a=4, b=2 and c= 3, Then a(b2-c2)+b(c2-a2)+c(a2-b2) = (a-b)*(b-c)*(c-a) = (4-2)*(2-3)*(3-4) = 2
Now let’s see different ways to compute a(b2-c2)+b(c2-a2)+c(a2-b2)
Method-1: Java Program to Compute a(b2-c2)+b(c2-a2)+c(a2-b2) where Value of a, b, and c are Given By Using Static Input Value
Approach:
- Declare and initialize three integer variables say
a
,b
, andc
. - By using the formula compute a(b2-c2)+b(c2-a2)+c(a2-b2)
- Print the result.
Program:
class Main { public static void main(String[] args) { //declare the first integer variable with a integer value int a= 4; System.out.println("a= " +a); //declare the second integer variable with a integer value int b= 2; System.out.println("b= "+b); //declare the second integer variable with a integer value int c= 3; System.out.println("c= "+c); //declare another integer variable and assigned the formulated value to it. int d=(a-b)*(b-c)*(c-a); System.out.println("a(b2-c2)+b(c2-a2)+c(a2-b2)= "+d); } }
Output: a= 4 b= 2 c= 3 a(b2-c2)+b(c2-a2)+c(a2-b2)= 2
Method-2: Java Program to Compute a(b2-c2)+b(c2-a2)+c(a2-b2) where Value of a, b, and c are Given By Using User Input Value
Approach:
- Declare three integer variables say
a
,b
, andc
. - Take the value of a, b, and c as user input by using Scanner class.
- Then By using the formula compute a(b2-c2)+b(c2-a2)+c(a2-b2)
- Print the result.
Program:
import java.util.Scanner; class Main { public static void main(String[] args) { //create object of scanner class. Scanner sc=new Scanner(System.in); System.out.print("a= "); //Take the first input from the user. int a= sc.nextInt(); System.out.print("b= "); //Take the second input from the user. int b= sc.nextInt(); System.out.print("c= "); //Take the first input from the user. int c= sc.nextInt(); //declare another integer variable and assigned the formulated value to it. int d=(a-b)*(b-c)*(c-a); System.out.println("a(b2-c2)+b(c2-a2)+c(a2-b2)= "+d); } }
Output: a= 234 b= 12 c= 32 a(b2-c2)+b(c2-a2)+c(a2-b2)= 896880
Method-3: Java Program to Compute a(b2-c2)+b(c2-a2)+c(a2-b2) where Value of a, b, and c are Given By Using User Defined Method
Approach:
- Declare three integer variables say
a
,b
, andc
. - Take the value of a, b and c as user input by using Scanner class.
- Then call a user defined method say
computeValue()
and pass a, b, and c as parameter. - Then inside method by using the formula compute a(b2-c2)+b(c2-a2)+c(a2-b2)
- Print the result.
Program:
import java.util.Scanner; class Main { public static void main(String[] args) { //create object of scanner class. Scanner sc=new Scanner(System.in); System.out.print("a= "); //Take the first input from the user. int a= sc.nextInt(); System.out.print("b= "); //Take the second input from the user. int b= sc.nextInt(); System.out.print("c= "); //Take the first input from the user. int c= sc.nextInt(); //call the function computeValue(a,b,c); } //define the method public static void computeValue(int a, int b,int c) { //declare another integer variable and assigned the formulated value to it. int d=(a-b)*(b-c)*(c-a); System.out.println("a(b2-c2)+b(c2-a2)+c(a2-b2)= "+d); } }
Output: a= 10 b= 99 c= 8 a(b2-c2)+b(c2-a2)+c(a2-b2)= 16198
Are you a job seeker and trying to find simple java programs for Interview? This would be the right choice for you, just tap on the link and start preparing the java programs covered to crack the interview.
Related Java Programs:
- Java Program to Compute a3(b-c)+b3(c-a)+c3(a-b) where Value of a, b and c are Given
- Java Program to Compute (b+c)(c+a)(a+b) where Value of a, b and c are Given
- Java Program to Compute (a+b+c)(b+c-a)(c+a-b)(a+b-c) where Value of a, b and c are Given
- Java Program to Compute (a+b+c)(bc+ca+ab)-abc where Value of a, b and c are Given