Double value


Tuesday, October 31, 2023 Difficulty: Easy

Objective

Write a Java program that requests the width (x) and height (y) of a rectangle and calculate the perimeter, area and diagonal.

  • Perimeter= sum of the four sides.
  • Area= base x height.
  • Diagonal= Pythagorean theorem.

Input

4
6

Output

Perimeter: 20
Area: 24
Diagonal: 7.211102550927978

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

Variables

Variables are an essential component in any programming language, and Java is no exception. In this post, we will explore the concept of variables in Java and how they are used in programming.

Data types

Practice with easy and intermediate Java exercises on different types of text, numeric or boolean data.

Fundamentals concepts
Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

CookieOwn and third party cookies to improve our services. If you go on surfing, we will consider you accepting its use.