Java Operator

 Program No 1:

Length and breadth of a rectangle are 5 and 7 respectively. Write a program to calculate the area and perimeter of the rectangle.


package its.a.program;


import java.util.Scanner;


public class ItsAProgram {

    public static void main(String[] args) {

      //area and paremeter of rectangle 

        int length=5;

        int breadth=7;//putting values of varaibles

        

        double area=length*breadth;

       double perimeter=2*(length+breadth);

       

              System.out.print("Area is =");


       System.out.println(area);

              System.out.print("Perimeter of rectangle is =");


       System.out.println(perimeter);

       

    }    

}

    


Program NO 2:

Write a program to calculate the perimeter of a triangle having sides of length 2,3 and 5 units


package its.a.program;


import java.util.Scanner;


public class ItsAProgram {

    public static void main(String[] args) {

      //perimeter of a triangle

        Scanner sc=new Scanner (System.in);

        

        System.out.print("Enter 1st number =");

       int firstSide=sc.nextInt();

       System.out.print("Enter 2nd number =");

      int secondSide=sc.nextInt();

       System.out.print("Enter 3rd number =");

       int thirdSide=sc.nextInt();

        double perimeter =firstSide+secondSide+thirdSide;

        System.out.print("Perimeter is ="+perimeter);

       

    }    

}

    


Program NO 3:
Write a program to add 8 to the number 2345 and then divide it by 3. Now, the modulus of the quotient is taken with 5 and then multiply the resultant value by 5. Display the final result.

package its.a.program;

public class ItsAProgram {
    public static void main(String[] args) {
        //perform calculation
        System.out.print("Ans is =");
      System.out.println((((8+2345)/3)%5)*5);
       
    }    
}
    




Program NO 4: 

Write a program to check if the two numbers 23 and 45 are equal.


package its.a.program;


public class ItsAProgram {

    public static void main(String[] args) {

        

    //check if the two numbers 23 and 45 are equal.

      int a=23;

      int b=45;

      System.out.print(a==b);

    }    

}











  

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.