






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Variation of arrays of objects
public class Rectangle { double length; double width; public void setdata(double l,double w) { length=l; width=w; } public void showdata() { System.out.println("the lenth is"+length+"width is"+width); double area=length*width; System.out.println("the area is"+area); } } import java.util.Scanner;public class Main{ public static void main(String[] args) { Rectangle rect[]= new Rectangle[5]; Scanner a= new Scanner(System.in); for(int k=0;k<5;k++) { rect[k]=new Rectangle(); } for(int i=0;i<5;i++) { System.out.println("enter length of rect"+i+1+":"); double length= a.nextDouble(); System.out.println("enter breadth of rect"+i+1+":"); double width= a.nextDouble(); rect[i].setdata(length,width); } for(int j=0;j<5;j++) { rect[j].showdata(); } } }
Variation of arrays of objects
public class Rectangle { double length; double width; Rectangle(double l,double w) { length=l; width=w; } public void showdata() { System.out.println("the length is"+length+"width is"+width); double area=length*width; System.out.println("the area is"+area); } } import java.util.Scanner; public class Main { public static void main(String[] args) { Rectangle rect[]= new Rectangle[5]; Scanner a= new Scanner(System.in); for(int i=0;i<5;i++) { System.out.println("enter length of rect"+i+1+":"); double length= a.nextDouble(); System.out.println("enter breadth of rect"+i+1+":"); double width= a.nextDouble(); rect[i]=new Rectangle(length,width); } for(int j=0;j<5;j++) { rect[j].showdata();
Math.ceil()
double x = 83.56; System.out.println(Math.c eil(x)); Output
Math.floor()
double x = 94.69; System.out.println(Math.floo r(x)); Ouput
Math.round() The Math.round() method rounds a float or double to the nearest integer using normal math round rules (either up or down). Here is a Java Math.round() example: Add 10 more math functions to this list double x = 79.52; System.out.println(Math.round(x)); OUTPUT: 80
THANK YOU !!!