Suppose a user wants to calculate the square of a number or the square root of a number, and display the results.
1
Expert's answer
2016-03-25T10:20:03-0400
import java.util.Scanner;
public class Square { public static void main(String[] args) { System.out.println("Input your number:"); Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); System.out.println("Square of a number: " + (n*n)); System.out.println("Square root of a number: " + Math.sqrt(n)); } }
Comments
Leave a comment