Page 64 - iPro_trackGPT_V5_Class8
P. 64

area = length * width;
                                // Perimeter of rectangle = 2 * (length + width)

                                perimeter = 2 * (length + width);
                                System.out.println("Area of the rectangle is: " + area);
                                System.out.println("Perimeter  of the rectangle  is: " +
                  perimeter);
                         }
                  }
                  Program 2: Write a program to find the amount to be paid.

                  public class Amount {
                         public static void main(String args[]) {
                                int unitPrice, units, amount;
                                unitPrice = 20;

                                units = 100;
                                                                                                  Output
                                amount = unitPrice * units;
                                System.out.println("Total amount to be paid: " + amount);
                         }
                  }
                  Program 3: Write a Java program to perform addition, subtraction, multiplication, and division
                  using arithmetic operators.

                  public class ArithmeticOperations {
                      public static void main(String[] args) {

                          int num1 = 10;

                          int num2 = 5;

                          int sum = num1 + num2;
                          int difference = num1 - num2;
                          int product = num1 * num2;                                            Output
                          double division = (double) num1 / num2;

                          System.out.println("Addition: " + num1 + " + " + num2 + " = "
                  + sum);
                          System.out.println("Subtraction: " + num1 + " - " + num2 + " =
                  " + difference);
                          System.out.println("Multiplication: " + num1 + " * " + num2 +
                  " = " + product);
                          System.out.println("Division: " + num1 + " / " + num2 + " = "
                  + division);
                      }

                  }


                    62    TrackGPT iPRO (V5.0)-VIII
   59   60   61   62   63   64   65   66   67   68   69