Skip to content

Instantly share code, notes, and snippets.

@MayankVikash
Created August 11, 2022 05:40
Show Gist options
  • Save MayankVikash/b9d6dfadbbe5559a0011d4efcf656a74 to your computer and use it in GitHub Desktop.
Save MayankVikash/b9d6dfadbbe5559a0011d4efcf656a74 to your computer and use it in GitHub Desktop.
import java.util.*;
public class ExpansionFormulas {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double ans;
System.out.println("Choose the Formula");
System.out.println("Enter 1 for (a+b)^2");
System.out.println("Enter 2 for (a-b)^2");
System.out.println("Enter 3 for (a^2 - b^2)");
System.out.println("Enter 4 for (a+b)^3");
System.out.println("Enter 5 for (a-b)^3");
int ip = sc.nextInt();
System.out.println("Enter the value of a and b");
double a = sc.nextDouble();
double b = sc.nextDouble();
if (ip ==1){
ans = a*a + 2*a*b + b*b;
System.out.println("Working:");
System.out.println("a*a + 2*a*b + b*b");
System.out.println(ans);
}
else if (ip == 2){
ans = a*a - 2*a*b + b*b;
System.out.println("Working:");
System.out.println("a*a - 2*a*b + b*b");
System.out.println(ans);
}
else if (ip ==3){
ans = (a+b) * (a-b);
System.out.println("Working:");
System.out.println("(a+b) * (a-b)");
System.out.println(ans);
}
else if (ip == 4){
ans = a*a*a + b*b*b + 3*a*b *(a+b);
System.out.println("Working:");
System.out.println("a*a*a + b*b*b + 3*a*b *(a+b)");
System.out.println(ans);
}
else if (ip == 5){
ans = a*a*a - b*b*b - 3*a*b *(a-b);
System.out.println("Working:");
System.out.println("a*a*a - b*b*b - 3*a*b *(a-b)");
System.out.println(ans);
}
else{
System.out.println("Wrong Choice");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment