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