Code example for Scanner

Methods: hasNextIntnextInt

0
		System.out
				.println("This program calculates the area and the circumference of a circle with a given radius.");
		System.out.println("Please give the radius of the circle in cm..");
		System.out.println("Radius:");
 
		input = new Scanner(System.in);
 
		if (input.hasNextInt()) {
 
			radius = input.nextInt();
 
			area = Math.PI * Math.pow(radius, 2);
			circumf = 2 * Math.PI * radius;
 
			DecimalFormat format = new DecimalFormat("#.##");
			System.out.println("The radius of the circle is "
					+ format.format(radius) + " cm.");
			System.out.println("The area of the circle is "
					+ format.format(area) + " square cm.");
			System.out.println("The circumference of the circle is "
					+ format.format(circumf) + " cm.");