How do you you Scanner method input marked Here is the out

How do you you Scanner method;

input ( ) marked!

Here is the output that I want to show --------------------------

Information for figure 1: Type 1) rectangle 2) triangle 3) circle (1)

height? (3.0)

width? (3.0)


Information for figure 2: Type 1) rectangle 2) triangle 3) circle (2)

base? (3.0)

height? (3.0)

  
rectangle area = 9.0

triangle area = 4.5


The rectangle seems to be bigger. -------------

Those things are available to shown as an output.

The rectangle seems to be bigger than the triangle.

The triangle seems to be bigger than the rectangle.

The triangle and rectangle seem to be equal.

Solution

Hi, Please find my code.

I have implemented for option=1, like that you can implement for other option by yourself by taking help from my code, so that you can also get some concept.

import java.util.Scanner;

public class Test {

  

   public static void main(String[] args) {

      

       // creating scanner method

       Scanner sc = new Scanner(System.in);

      

       int option;

      

       System.out.println(\"Type 1) rectangle 2) triangle 3) circle\");

       option = sc.nextInt();

      

       if(option == 1){

          

           System.out.print(\"height ? \");

           double height = sc.nextDouble();

           System.out.print(\"width ? \");

           double width = sc.nextDouble();

          

          

           System.out.println(\"Type 1) rectangle 2) triangle 3) circle\");

           option = sc.nextInt();

           if(option == 1){

               System.out.print(\"base ? \");

               double base = sc.nextDouble();

               System.out.print(\"height ? \");

               double height1 = sc.nextDouble();

              

               double rectArea = height*width;

               double triangleArea = height1*base*0.5;

              

               System.out.println(\"rectangle area = \"+rectArea);

               System.out.println(\"triangle area = \"+triangleArea);

              

               if(rectArea > triangleArea){

                   System.out.println(\"The rectangle seems to be bigger than the triangle.\");

               }else if(triangleArea > rectArea){

                   System.out.println(\"The triangle seems to be bigger than the rectangle.\");

               }else{

                   System.out.println(\"The triangle and rectangle seem to be equal.\");

               }

           }

       }

   }

}

/*

Sample output:

Type 1) rectangle 2) triangle 3) circle

1

height ? 3.0

width ? 3.0

Type 1) rectangle 2) triangle 3) circle

1

base ? 3.0

height ? 3.0

rectangle area = 9.0

triangle area = 4.5

The rectangle seems to be bigger than the triangle.

*/

How do you you Scanner method; input ( ) marked! Here is the output that I want to show -------------------------- Information for figure 1: Type 1) rectangle 2
How do you you Scanner method; input ( ) marked! Here is the output that I want to show -------------------------- Information for figure 1: Type 1) rectangle 2
How do you you Scanner method; input ( ) marked! Here is the output that I want to show -------------------------- Information for figure 1: Type 1) rectangle 2

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site