lesson 3.1 part 1

package lesson.pkg1; import java.util.*; //importing the Scanner class /** * * @author anfal */ public class computeArea { public static void main(String[] args) { //a program that calculates the area of any circle given its radius. Scanner input = new Scanner(System.in); //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(); if (radius >= 0) //if the condition is true { //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 + "."); } else // if the condition is false System.out.println("you entered an invalid number."); } }

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.