JAVA PROGRAMMING
Write a program a number and print its square and square root.
Answers
Answered by
10
The given problem is solved using language - Java.
import java.util.Scanner;
public class Brainly{
public static void main(String s[]){
Scanner sc=new Scanner(System.in);
double n,sq,sqrt;
System.out.print("Enter a number: ");
n=sc.nextDouble();
sc.close();
sq=n*n;
sqrt=Math.sqrt(n);
System.out.println("The square of "+n+" is: "+sq);
System.out.println("The square root of "+n+" is: "+sqrt);
}
}
- Take the number as input.
- To calculate square of the number, multiply the number by itself.
- To calculate the square root of the number, use Math.sqrt() function.
Enter a number: 2.0
The square of 2.0 is: 4.0
The square root of 2.0 is: 1.4142135623730951
Attachments:
anindyaadhikari13:
Thanks for the brainliest :)
Similar questions