Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AreaFinder
- {
- public static void main (String [] args)
- {
- int count = 1;
- String exit = "yes";
- do
- {
- System.out.println("To find area of rectangle, press r.\nTo find area of triangle, press t.\nTo find area of circle, press c.");
- Scanner in = new Scanner (System.in);
- String userinput = in.nextLine();
- if(userinput.equals("c"))
- {
- System.out.println("\nPlease type the radius.");
- double radius;
- radius = in.nextDouble ();
- double areaC = (radius*radius)*Math.PI;
- System.out.println("\nThe area of a circle with radius " + radius + " is: \n" + areaC);
- }
- else if(userinput.equals("r"))
- {
- System.out.println("\nPlease type length and width as l w.");
- double length, width;
- length = in.nextDouble ();
- width = in.nextDouble ();
- double areaR = (length*width);
- System.out.println("\nThe area of a rectangle with length:" + length + " and width:" + width + " is: \n" + areaR);
- }
- else if(userinput.equals("t"))
- {
- System.out.println("\nPlease type base and height as b h.");
- double base, height;
- base = in.nextDouble ();
- height = in.nextDouble ();
- double areaT = (base*height)/2;
- System.out.println("\nThe area of a triangle with base:" + base + " and height:" + height + " is: \n" + areaT);
- }
- else
- {
- System.out.println("Please type r t or c dummy.");
- }
- System.out.println("Would you like to do another problem(yes/no)");
- exit = in.next();
- //Program will preform as long as exit is "yes"
- }
- while (exit.contains("yes"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement