HOW TO SOLVE (A+B) WHOLE SQUARE IN JAVA BY TAKING INPUT FROM USER.
Formula :-
(a + b)2 = a2 + 2ab + b2
INPUT:-
import java.util.Scanner;
public class example{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a,b,c;
System.out.println("Enter your first number : ");
a=sc.nextInt();
System.out.println("Enter your second number : ");
b=sc.nextInt();
c=a*a+2*a*b+b*b;
System.out.println("(a+b) Whole square is : ");
System.out.println(c);
}
}
0 Comments