Advertisement
cgorrillaha

Intro Java Areas with Scanner

Sep 18th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4.   public static void main(String[] args) {
  5.     /*
  6.     can support decimal values: float and double
  7.     integer types: byte short int long
  8.     */    
  9.  
  10.     //declaring variables
  11.     Scanner scan;
  12.     double areaOfCircle;
  13.     int areaOfRect;
  14.  
  15.     int length, width, radius;
  16.     final double PI=Math.PI;
  17.  
  18.     //inputs
  19.     scan=new Scanner(System.in);
  20.     length=15;
  21.     width=24;
  22.     radius=5;
  23.     //prompt for length and width
  24.     System.out.println("Please enter the length of the rectangle");
  25.     //input using Scanner
  26.     length=scan.nextInt();
  27.  
  28.     System.out.println("Please enter the width of the rectangle");
  29.     //input using Scanner
  30.     width=scan.nextInt();
  31.    
  32.     System.out.println("Please enter the radius of the circle");
  33.     //input using Scanner
  34.     radius=scan.nextInt();
  35.  
  36.     //calcs
  37.     areaOfRect=length*width;
  38.     areaOfCircle=radius*radius*PI;
  39.     areaOfCircle=Math.pow(radius,2)*PI;
  40.  
  41.     //outputs
  42.     System.out.println("Area of a rectangle with length: "+length+
  43.                         " and a witdth: "+width+ " is: "+areaOfRect);
  44.     System.out.println("Area of a circle with radius: "+radius+
  45.                         " is: "+areaOfCircle);
  46.   }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement