Blog
Calculate percentage of student on basis of 5 subject marks and also give grades on basis of percentage
01/01/2002 08:14
*/
public class Studentpercentage
{
public static void main(String args[])
{
String Student;
int a=75;
int b=72;
int c=71;
int d=79;
int e=69;
int f=a+b+c+d+e;
int percentage=f*100;
double g=percentage/400;
System.out.println("Husain");
System.out.println(g);
if(g>=90)
{
System.out.println("A grade");
}
if(g>=80&&g<=90)
{
System.out.println("B grade");
}
if(g>=70&&g<=80)
{
System.out.println("c grade");
}
}
Write a program to print febonicci series
01/01/2002 08:13
public class febonicci
{
public static void main(String args[])
{
int c;
int a=0;
int b=1;
System.out.println(a+" "+b);
for(int i=3;i<=20;i++)
{
c=a+b;
a=b;
b=c;
System.out.println(c);
}
}
}
To print area of rectangle
18/03/2013 08:28
public class areaofrectangle
{
public static void main(String args[])
{
int length=5;
int breadth=9;
int area=length*breadth;
System.out.println("area of rectangle is"+" "+area);
}
}
Write a program with function "convert" which takes the temperature in Celsius and converts the equivalent Fahrenheit value
20/03/2013 00:10
public class abc
{
static double a=1.8;
static double c=100;
static double b=32;
static void convert()
{
double farenheit=a*c+b;
System.out.println(farenheit);
}
public static void main(String args[])
{
convert();
}
}
Write a program with function "calculate" to except the time in minutes and convert in hours
20/03/2013 00:23
public class converter
{
static double minute=30;
static double b=60;
static void calculate()
{
double hour=minute/b;
System.out.println(hour);
}
public static void main(String args[])
{
calculate();
}
}
To call swap programs into main method using third way
01/01/2002 07:49This type of calling function into main method is called as "call by reference" method
public class reference
{
int a=10;
int b=15;
void swap(reference ob1)
{
int c;
c=ob1.a;
ob1.a=ob1.b;
ob1.b=c;
System.out.println(a);
System.out.println(b);
}
public static void main(String args[])
{
reference ob1=new reference();
ob1.swap(ob1);
}
}
Same program can be made by using "Static" keyword
public class reference
{
static int a=10;
static b=15;
static void swap()
{
int c;
c=a;
a=b;
b=c;
System.out.println(a);
System.out.println(b);
}
public static void main(String args[])
{
swap();
}
}
Another way by which we can call swap program into main method f
01/01/2002 07:42
This method of calling is also called as "call by values"
public class values
{
void swap(int a,int b)
{
int c;
c=a;
a=b;
b=c;
System.out.println(a);
System.out.println(b);
}
public static void main(String args[])
{
int x=10;
int y=15;
values ob1=new values();
ob1.swap(x,y);
}
}
This program is used for swaping values ie interchanging one value with another eg: int a=9; int b=10; now interchange int a=10; int b=9; * also overloaded functions are explain ie having same name of function but different parameters used for it
16/03/2013 20:07This is also the simple method of calling functions in main method
public class xyz
{
void swap(int a,int b)
{
int c;
c=a;
a=b;
b=c;
System.out.println(a);
System.out.println(b);
}
void swap()
{
int a=5;
int b=6;
int c;
c=a;
a=b;
b=c;
System.out.println(a);
System.out.println(b);
}
public static void main(String args[])
{
xyz obj=new xyz();
obj.swap(8,9);
xyz obj1=new xyz();
obj.swap();
}}
Write a program with overloaded function volume() to calculate the volume of cube,cuboid and a cylinder
01/01/2002 08:01
public class husain
{
void volume(int l,int b,int h)
{
int volume=l*b*h;
System.out.println(volume);
}
void volume()
{
int side=5;
int volume=side*side*side;
System.out.println(volume);
}
void volume(double a,double b,double c)
{
double d=a*b*c;
double volume=d*b;
System.out.println(volume);
}
public static void main(String args[])
{
husain obj=new husain();
obj.volume(5,10,15);
husain ob1=new husain();
ob1.volume();
husain ob2=new husain();
ob2.volume(3.14,5,10);
}
}
volume of cylinder is(3.14r2h)
Write a program and define the function "area" to find area of rectangle square and triangle.
16/03/2013 13:22Here is it
public class recsqutri
{
void area(int l,int b)
{
int area=l*b;
System.out.println(area);
}
void area()
{
int side=5;
int area=side*side;
System.out.println(area);
}
void area(double a,double b,double c)
{
double area=a*b*c;
System.out.println(area);
}
public static void main(String args[])
{
recsqutri obj=new recsqutri();
obj.area(5,6);
recsqutri obj1=new recsqutri();
obj1.area();
recsqutri obj2=new recsqutri();
obj2.area(0.5,2,1);
}
}