Blog
Write a program to calculate area of rectangle. Define a parametrized function "rect" to find area of rectangle
20/03/2013 00:45
public class rectangle
{
void rect(int a,int b)
{
int area=a*b;
System.out.println(area);
}
public static void main(String args[])
{
rectangle ob1=new rectangle();
ob1.rect(5,10);
}
}
Write a program describing different methods of defining functions and calling them into main method
16/03/2013 20:09Here are 4 methods of defining functions
public class functons
{
void add1()
{
int a=7;
int b=9;
int c=a+b;
System.out.println(c);
}
void add2(int a,int b)
{
int c=a+b;
System.out.println(c);
}
int add3()
{
int a=9;
int b=7;
int c=a+b;
return(c);
}
int add4(int a,int b)
{
int c=a+b;
return(c);
}
Here is the method of calling them into "main" method
public static void main(String args[])
{
functons ob1=new functons();
ob1.add1();
functons ob2=new functons();
ob2.add2(12,89);
functons ob3=new functons();
System.out.println(ob3.add3());
functons ob4=new functons();
System.out.println(ob4.add4(90,86));
}
}