Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Variable might not have been initialized

807598Oct 19 2006 — edited Oct 21 2006
I get errors when trying to compile the following code that say each of the 5 variables might not have been initialized.
I guess I could initialize them all to zero when declaring them, but this seems an innacurate representation of the situation.
Is there another way around this error?
import java.io.*;
import java.lang.*;

public class Circle03
{
    public static void main(String[]args)
    {
	    try
		{
		    double centreX, centreY, secondX, secondY, diameter;
		    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		    String str = "";
		    
			    System.out.print("\nEnter the X coordinate of the centre: ");
			    str = in.readLine();
			    try
				{
				    centreX = Double.parseDouble(str);
				}
			    catch (NumberFormatException e)
				{
				    System.out.print("\nSorry, input numbers only.\nTry again.\n ");
				}

			    System.out.print("\nEnter the Y coordinate of the centre: ");
			    str = in.readLine();
			    try
				{
				    centreY = Double.parseDouble(str);
				}
			    catch (NumberFormatException e)
				{
				    System.out.print("\nSorry, input numbers only.\nTry again.\n ");
				}


			    System.out.print("\nEnter the X coordinate of the 2nd point: ");
			    str = in.readLine();
			    try
				{
				    secondX = Double.parseDouble(str);
				}
			    catch (NumberFormatException e)
				{
				    System.out.print("\nSorry, input numbers only.\nTry again.\n ");
				}

			    System.out.print("\nEnter the Y coordinate of the 2nd point: ");
			    str = in.readLine();
			    try
				{
				    secondY = Double.parseDouble(str);
				}
			    catch (NumberFormatException e)
				{
				    System.out.print("\nSorry, input numbers only.\nTry again.\n ");
				}


			    System.out.print("\nEnter the diameter: ");
			    str = in.readLine();
			    try
				{
				    diameter = Double.parseDouble(str);
				}
			    catch (NumberFormatException e)
				{
				    System.out.print("\nSorry, input numbers only.\nTry again.\n ");
				}


			    System.out.print("\nThis is what you have entered\nCentre X = " + centreX +
 "\nCentre Y = " + centreY +
 "\n2nd X = " + secondX +
 "\n2nd Y = " + secondY +
 "\nDiameter = " + diameter + "\n");
		}
	    catch (IOException e)
		{
		    
			e.printStackTrace();
		}
    }
}
Message was edited by:
carpark
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2006
Added on Oct 19 2006
9 comments
682 views