Lesson 2.2 scanner

package lesson.pkg1; import java.util.*; //importing the Scanner class /** * * @author anfal */ public class computeArea { public static void main(String[] args) { Scanner input = new Scanner(System.in); //a program that calculates the area of any circle given its radius. //1.prompt user to inter radius System.out.println("please input a radius: "); //2. int radius and read it from the user int radius = input.nextInt(); //3. double area double area; //4. area <-- radius * radius * PI area = Math.pow(radius, 2) * Math.PI; //5. print area System.out.println("the circle of radius: " + radius + ", has the area of: " + area + "."); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.