Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guys. I\'m just looking for some help here. I\'m looking to code in JAVA. En

ID: 3776786 • Letter: H

Question

Hey guys. I'm just looking for some help here. I'm looking to code in JAVA.

Enter the first side (as a decimal): 20.5
Enter the second side (as a decimal): 15.0
The area is 307.5
The perimeter is: 71.0

Enter the radius (decimal): 30.2
The area is: 2,865.2557
The circumference is: 189.752

Enter the height of the triangle (decimal): 3.0
Enter the base of the triangle (decimal): 4.0
The area is: 6.0
The perimeter is

public static void main (String[] args)
{
double side1 = 0.0;
double side2 = 0.0;
double radius = 0.0;
double base = 0.0;
double height = 0.0;
final double PI = 3.14159;

System.out.print("Enter the first side ");
Scanner inData; // A class that reads input
inData = new Scanner(System.in);
System.out.print(" Enter the length of a side ");
side1 = inData.nextDouble();
System.out.print(" Enter the length of second side ");
   side2 = inData.nextDouble();
System.out.println(" The area is " + side1 * side2 + " ");
System.out.println("The perimeter is " + 2 * (side1 + side2));

Explanation / Answer

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.lang.Math.*;


/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
   public static void main (String[] args)
{
double side1 = 0.0;
double side2 = 0.0;
double radius = 0.0;
double base = 0.0;
double height = 0.0;
final double PI = 3.14159;
  
Scanner inData; // A class that reads input
inData = new Scanner(System.in);
System.out.print(" Enter the first side (as a decimal): ");
side1 = inData.nextDouble();
System.out.print(" Enter the second side (as a decimal): ");
side2 = inData.nextDouble();
double areaR=side1*side2; //calculating area of rectangle
double periR=(side1*2.0d)+(side2*2.0d); //calculating perimeter of rectangle
System.out.println(" The area is "+areaR+" ");
System.out.println("The perimeter is : " +periR);
System.out.print(" Enter the radius (decimal): ");
radius=inData.nextDouble();
double areaC=PI*radius*radius; //calculating area of circle
double periC=PI*radius*2.0d; //calculating perimeter of rectangle
System.out.println(" The area is: "+areaC+" ");
System.out.println("The circumference is: " +periC);
System.out.print(" Enter the height of the triangle (decimal): ");
height=inData.nextDouble();
System.out.print(" Enter the base of the triangle (decimal): ");
base=inData.nextDouble();
double areaT=(1.0/2.0)*base*height;//calculating area of triangle
double periT=Math.sqrt((height*height)+(base*base))+height+base;//calculating perimeter of triangle
System.out.println(" The area is: "+areaT+" ");
System.out.println("The perimeter is : " +periT);
  
  
}
  
}

/****OUTPUT******

Enter the first side (as a decimal):
Enter the second side (as a decimal):
The area is 307.5

The perimeter is : 71.0

Enter the radius (decimal):
The area is: 2865.2557435999997

The circumference is: 189.75203599999998

Enter the height of the triangle (decimal):
Enter the base of the triangle (decimal):
The area is: 6.0

The perimeter is : 12.0
****OUTPUT**********/

/* Please ask in case of any doubt,Thanks.*/