JAVA

How to calculate the area of a parallelogram and Swap two numbers Java

we will explore two fundamental concepts in mathematics and programming. First, we’ll delve into the mathematical concept of finding the area of a parallelogram. Then, we’ll shift our focus to a common programming task—swapping two numbers in Java. Whether you’re a student trying to grasp geometry or a Java developer looking for a code snippet to swap variables, you’re in the right place!

How to calculate the area of a parallelogram and Swap two numbers without using a temporary variable. we have tried to write to java programming to calculate or to find the area Such as.

What is a parallelogram:-

A parallelogram is a special type of quadrilateral that has equal and parallel opposite sides.

Mathematics and programming often go hand in hand, and in this blog post, we’ll explore two interesting concepts: calculating the area of a parallelogram and swapping two numbers in the Java programming language. These topics may seem unrelated at first, but they both offer valuable insights into mathematical calculations and programming logic. Let’s dive in!

Calculating the Area of a Parallelogram:

A parallelogram is a four-sided polygon with opposite sides that are parallel and equal in length. To calculate its area, you’ll need the base length (b) and the height (h) perpendicular to the base. The formula for finding the area of a parallelogram is:

Swap two numbers without using a temporary variable

public class ChangeNumbers{
 public static void main(string []args){
 
  int first=10,second =20;
  System.out.println("First Number ="+first);        System.out.println("First Number ="+second);		
	
    first = first-second;
    second = first+second;
    first = second-first;

  System.out.println("First Number ="+first);            System.out.println("First Number ="+second);	
}

}

// OUTPUT
<--  Before swapping -->
first = 10;
second = 20;
<-- After swapping-->
first = 20;
second = 10;
 

Java Program To Find Area of Parallelogram – Programs

import java.util.Scanner;
class AreaOfParallelogram 
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the height:");
         double d1= s.nextDouble();
        System.out.println("Enter the breadth:");
         double d2= s.nextDouble()
          
          double  area=(d1*d2) ;
      System.out.println("Area of Parallelogram is: " + area);      
   }
}

Enter the height:5
Enter the breadth: 5
//OUTPUT
 Area of Parallelogram is: 25.0

Related Articles

4 Comments

  1. I may need your help. I tried many ways but couldn’t solve it, but after reading your article, I think you have a way to help me. I’m looking forward for your reply. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button