class Box { int l,b,h; int volume( ) { return(l*b*h); } } class Abc { public static void main(String args[ ]) { Box b1= new Box( ); b1.l=4; b1.b=6; b1.h=10; System.out.println(“Length of box is = 4″); System.out.println(“Breadth of box is = 6″); System.out.println(“Height of box is = 10″); System.out.println(“Volume of box is =”+b1.volume( )); } }
package ex4; import java.util.Scanner; class reverse { int sum = 0; int getvalue() { return sum; } } public class Ex4 { public static void main(String[] args) {
Scanner s = new Scanner(System.in); reverse nm = new reverse(); int m,rv=0,nber,sum=0; System.out.println("Plz enter the int number");
m = s.nextInt(); nber = m;
while (nber!=0) { rv = rv*10; rv = rv+nber%10; nber = nber/10; sum+=rv; } System.out.println("Reverses " +rv); double result = nm.getvalue(); System.out.println("These Reversed number is " +sum); } }
b))) ***Write a program to calculate the Volume of a Box using Method.
ReplyDelete=> class Box()
{
double width,height,depth;
void volume()
{
System.out.println(width*height*depth);
}
}
class BoxDemo
{
public static void main()
{
Box mybox1=newbox();
mybox1.width=20;
mybox1.heigth=15;
mybox1.depth=20;
mybox1.volume();
}
}
double volume()
{
return width*height*depth;
}
{
vol=mybox1.volume();
System.out.println(vol);
}
This comment has been removed by the author.
ReplyDeleteb) Write a program to calculate the Volume of a Box using Method.
ReplyDeletepublic class Methode {
double width;
double height;
double depth;
void claculatevolum()
{
double vol;
width = 10;
height = 20;
depth = 15;
vol = width*height*depth;
System.out.println("The Volume is : " +vol);
}
}
public class Mybox {
public static void main(String[] args) {
Methode m = new Methode();
m.claculatevolum();
}
}
******* How to access the instance variable using Method?*******
ReplyDeleteSolution:
source code:
Instance variables using method:
public class Rectangle
{
double length;
double breadth;
}
//This class declares an object of type Rectangle.
class RectangleDemo
{
public static void main(String args[])
{
Rectangle myrect1 = new Rectangle();
Rectangle myrect2 = new Rectangle();
double area1,area2;
//assign values to myrect1 instance variables
myrect1.length = 15;
myrect1.breadth = 25;
//compute area of Rectangle
area1 = myrect1.length * myrect1.breadth;
System.out.println("Area of Rectangle 1 : " + area1);
//assign values to myrect2 instance variables
myrect2.length = 15;
myrect2.breadth = 25;
//compute area of Rectangle
area2 = myrect2.length * myrect2.breadth;
System.out.println("Area of Rectangle 2 : " + area2);
}
}
Q:write a program Java program using method :
ReplyDeleteohammad Ashraful Hasan Sobuj
My Batch- 46th
My Department :CSE
My ID 201420656
package Box;
class sobuj
{
double width;
double height;
double depth;
double volume()
{
return(width*height*depth);
}
}
public class Box {
public static void main(String[] args) {
sobuj mybox1 = new sobuj();
sobuj mybox2 = new sobuj();
double vol;
mybox1.width=100;
mybox1.height=200;
mybox1.depth=150;
mybox2.width=200;
mybox2.height=250;
mybox2.depth=110;
vol = mybox1.volume();
System.out.println("Volume of box1 is: " +vol);
vol = mybox2.volume();
System.out.println("\nVolume of box2 is: "+vol);
System.out.println();
}
}
Q:write a program Java program using method :
ReplyDeleteSharmin Akter
My Batch- 46th
My Department :CSE
My ID 201420769
package Box;
class Sharmin
{
double width;
double height;
double depth;
double volume()
{
return(width*height*depth);
}
}
public class Box {
public static void main(String[] args) {
Sharmin myboxa = new Sharmin();
Sharmin myboxb = new Sharmin();
double vol;
myboxa.width=100;
myboxa.height=200;
myboxa.depth=150;
myboxb.width=200;
myboxb.height=250;
myboxb.depth=110;
vol = myboxa.volume();
System.out.println("Volume of boxa is: " +vol);
vol = myboxb.volume();
System.out.println("\nVolume of boxb is: "+vol);
System.out.println();
}
}
ID-201420406
ReplyDeleteBatch-46th
class Box
{
int l,b,h;
int volume( )
{
return(l*b*h);
}
}
class Abc
{
public static void main(String args[ ])
{
Box b1= new Box( );
b1.l=4;
b1.b=6;
b1.h=10;
System.out.println(“Length of box is = 4″);
System.out.println(“Breadth of box is = 6″);
System.out.println(“Height of box is = 10″);
System.out.println(“Volume of box is =”+b1.volume( ));
}
}
ID-201421068
ReplyDeleteBatch-46th
package ex4;
import java.util.Scanner;
class reverse {
int sum = 0;
int getvalue()
{
return sum;
}
}
public class Ex4 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
reverse nm = new reverse();
int m,rv=0,nber,sum=0;
System.out.println("Plz enter the int number");
m = s.nextInt();
nber = m;
while (nber!=0) {
rv = rv*10;
rv = rv+nber%10;
nber = nber/10;
sum+=rv;
}
System.out.println("Reverses " +rv);
double result = nm.getvalue();
System.out.println("These Reversed number is " +sum);
}
}