package org.launchcode.java.studios.areaofacircle; import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a radius"); double radius = input.nextDouble(); double area = 3.14 * radius * radius; System.out.println("Area of circle is :" + area); } } ////Here it is with an if/else statement for negative numbers package org.launchcode.java.studios.areaofacircle; import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a radius"); double radius = input.nextDouble(); double area = 3.14 * radius * radius; if (radius < 0){ System.err.println("Radius must be a positive int."); //System.exit(status:1); }else { System.out.println("Area of circle is :" + area); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter