Computer Science, asked by Atlas99, 4 hours ago

JAVA PROGRAMMING

Write a program a number and print its square and square root.​

Answers

Answered by anindyaadhikari13
10

\textsf{\large{\underline{Solution}:}}

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);

   }

}

\textsf{\large{\underline{Explanation}:}}

  • 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.

\textsf{\large{\underline{Sample I/O}:}}

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