Computer Science, asked by AmyG93017, 10 months ago

Write the code to input a number and print the square root. Use the absolute value function to make sure that if the user enters a negative number, the program does not crash.

Answers

Answered by as9099401
0

Answer:

import java.util.Scanner;

class SqareRoot{

public static void main(String args[]){

System.out.print("Enter the number:") ;

Sanner sc = new Scanner(System.in);

double n = sc.nextInt();

double a = Math.abs(n);

double s = Math.sqrt(a);

System.out.println("Square root of "+n+" is = "+a) ;

}

}

Similar questions