This is my assignment, before some of you complain, I finished it. It works all I want is something that is in the back of my head bugging me. If a user was to input a letter instead of a number how do I keep the program from crashing and instead print an error? I've tried google and I've tried looking around.
import java.util.Scanner;
public class Circle
{
public static void main(String[] arg)
{
//create new scanner
Scanner input = new Scanner(System.in);
//declare variables
double radius;
double diameter;
double circum;
double pi = Math.PI;
//Ask the question
System.out.print("Please Enter a Radius: ");
//create add proper data/calculations to variables
radius = input.nextDouble();
diameter = 2*radius;
circum = 2*(pi*radius);
System.out.println("Diameter: "+diameter);
System.out.println("Circumference: "+circum);
}
}