Where am I getting it wrong?
IDE exeption "The local variable answer may not have been initialized" package com.operators; import java.util.Scanner; public class SquareRoot { //@MMS public static void main(String[] args) { String answer; do { //Ask for user input System.out.print("Insert a number to calculate: "); //User types number to be calculated Scanner sc = new Scanner(System.in); double a; a = sc.nextDouble(); //Calculates square root if user types negative number if (a <= 0) { double ans = Math.sqrt(a*-1); System.out.println("The square root of "+a +" is " +ans+"i"); } //calculates square root if user types positive number else { double ans = Math.sqrt(a); System.out.println("The square root of "+a +" is " +ans); System.out.println("Do you want to calculate another number? YES or NO\n"); answer = sc.next(); sc.close(); } } while (answer.equalsIgnoreCase("YES")); } }