JAVA PROGRAM
FIRST TERM
Basic structure of java program
class <class name>
{
public static void main( )
{
Code/java statement
}
}
class <class name>
{ // start of the class
public static void main( )
{ // start of the main method
code
} // end of the main method
} // end of the class
Output statement
Java language use the following statement to display messages or information or values -[Link]( “message ”);
WAP to display your country name and its capital name.
class country
{
public static void main()
{
[Link]("INDIA");
[Link]("DELHI");
}
}
WAP to display your name, school name and city name.
class school
{
public static void main()
{
[Link]("Shree");
[Link]("LOYOLA School,Bhubaneswar");
[Link]("Bhubaneswar");
}
}
WAP to display your parents name and address in separate line.
class parent
{
public static void main()
{
[Link](" Father name");
[Link]("Mother Name");
[Link]("Bhubaneswar");
}
}
WAP to display four friends name.
class Friend
{
public static void main()
{
[Link](“ Shree”);
[Link](“Shehan”);
[Link](“ Sita”);
[Link](“Rama”);
}
}
Data type : Different types of data (used) supported by java language (compiler) are called data types.
They specify size and type of any standard values.
(We discuss only two data type .)
int- It is a data type which stores(refer ) both +ve and –ve integers.
Variable- are the names you give to computer memory location which are used to store (one)value in computer program. The value of a variable can vary within the
program.
Syntax to declare variable NAME
datatype variablename;
or
datatype var1, var2, var3, varN;
Ex: int num1,num2,sum;
int roll;
Syntax to assign value to a variable
Variableame=value;
Ex: num1=23;
num2=67; roll=1;
int roll;
roll=16;
[Link]( roll);
Output
16
[Link]( “roll”);
Output
roll
[Link]( “Roll=”+roll);
Output
Roll=16
WAP to assign length=36 meter ,breadth=20meter of a rectangle, calculate and display area and perimeter of the rectangle.
class rect
{
public static void main()
{
int len,br,ar,pr;
len=36;
br=20;
ar=len*br;
pr=2*( len+br);
[Link](ar);
[Link](pr);
}
}
WAP to assign side=25 meter of square, calculate and display its area and perimeter.
class Square
{
public static void main()
{
int s,ar,pr;
s=25;
ar=s*s;
pr=4*s;
[Link](ar);
[Link](pr);
}
}
WAP to a assign length=14 m,width=8m, height= 6m of cuboid, calculate and display its volume
(length ×width×height) .
class cuboid
{
public static void main()
{
int l,w,h,v;
l=14;
w=8;
h=6;
v= l*w*h;
[Link](v);
}
}
WAP to assign side=20m of cube, calculate an display its volume(s 3) .
class cube
{
public static void main()
{
int s,v;
s=20;
v=s*s*s;
[Link](vol);
}
}
WAP to assign two number a=25 and b=7 calculate and display quotient and remainder .
class Calc
{
public static void main()
{
int a,b,qt,rem;
a=25; b=7;
qt=a/b ;
rem=a%b;
[Link](qt);
[Link](rem);
}
}
WAP to assign two number a=25 and b=7 calculate and display sum,difference and product .
class Calc
{
public static void main()
{
int a,b,sum,diff,prod;
a=25; b=7;
sum=a+b;
diff=a-b;
prod= a*b;
[Link](sum);
[Link](diff);
[Link](prod);
}
}
FINAL TERM
Computer Language
To communicate with the computers, we need some languages. These are computer languages.
The computer language is defined as code or syntax which is used to write programs or any specific applications. The computer
language is used to communicate with computers.
Instruction
An instruction is an order given to a computer processor by a computer program.
Program
A program is a set of instructions that a computer follows in order to perform a particular task.
Software
Software is a set of instructions, data or programs used to operate computers and execute specific tasks.
Java Language
Basic structure of java program
class <class name>
{ // start of the class
public static void main( )
{ // start of the main method
code
} // end of the main method
} // end of the class
Output statement
Java language use the following statement to display messages or information or values -[Link]( “message ”);
Data type : Different types of data (used) supported by java language (compiler) are called data types.
They specify size and type of any standard values.
(We discuss only two data type .)
int- It is a data type which stores(refer ) both +ve and –ve integers.
double- It is a data type which stores (refer ) both +ve and –ve decimal number.
Variable- are the names you give to computer memory location which are used to store (one)value in computer program. The value of a
variable can vary within the program.
Syntax to declare variable NAME
datatype variablename;
or
datatype var1, var2, var3, varN;
Ex: int num1,num2,sum;
int roll;
double mark,salary;
double tax;
Syntax to assign value to a variable
Variableame=value;
Ex: num1=23;
num2=67; roll=1;
We can also assign value to a variable and declare in the same statement.
int Len=36, br=20;
tax=12.0;
int roll;
roll=16;
[Link]( roll);
Output
16
[Link]( “roll”);
Output
roll
[Link]( “Roll=”+roll);
Output
Roll=16
[Link] to assign num=14 . Calculate and print square and cube of num.
class calc
{
public static void main()
{
int num,cb,sq;
num=14 ;
sq=num*num;
cb=num*num*num;
[Link](sq);
[Link](cb);
}
}
[Link] to assign length=45.7 meter ,breadth=32.8meter of a rectangle, calculate and display area and perimeter of the rectangle.
class rect
{
public static void main()
{
double len,br,ar,pr;
len=45.7;
br=32.8;
ar=len*br;
pr=2*( len+br);
[Link](ar);
[Link](pr);
}
}
[Link] to assign side=22.5 meter of square, calculate and display its area and perimeter.
class Square
{
public static void main()
{
double s,ar,pr;
s=22.5;
ar=s*s;
pr=4*s;
[Link](ar);
[Link](pr);
}
}
[Link] to a assign length=24.5 m,width=18m, height= 9.6m of cuboid, calculate and display its volume
(l ×w×h) and surface area(2×l×h+2×w×h+2×w×l).
class cuboid
{
public static void main()
{
double l,w,h,vol,sa;
l=24.5;
w=18.0;
h=9.6;
vol= l*w*h;
sa=2*l*h+2*w*h+2*w*l;
[Link](vol);
[Link](sa);
}
}
Q5. WAP to assign side=17.3m of cube, calculate an display its volume(s3) and surface area(6*s*s).
class cube
{
public static void main()
{
double s,vol,sa;
s=17.3;
vol=s*s*s;
sa=6*s*s;
[Link](vol);
[Link](sa);
}
}
Q6. WAP to assign radious=21.5m of circle, calculate an display its area( A=π r 2 ) and circumference(2 πr ) .
class Circle
{
public static void main()
{
double rad,ar,cir,pi;
pi=3.141;
rad=21.5;
ar=pi*rad*rad;
cir=2*pi*rad;
[Link](ar);
[Link](cir);
}
}
[Link] to assign amount=Rs4525, rate=8.5% per month ,time=16month, calculate and display simple interest(si=(am*rt*mn)/100).
class simple
{
public static void main()
{
double si,am,rt,mn;
am=4525.0; rt=8.5; mn=16.0;
si=(am*rt*mn)/100;
[Link](si);
}
}
[Link] to assign temperature in Celsius=45 degree convert into Fahrenheit and display .
F=(c*9/5)+32
class Temp
{
public static void main()
{
double c ,F;
c =45.0;
F=(c*9.0/5.0)+32.0;
[Link](F);
[Link](c);
}
}
[Link] to assign two number a=45.5 and b=10.0, calculate and print the followings a+b, a-b, a*b and a/b .
class Calc
{
public static void main()
{
double a,b,sum,diff,prod, qt;
a=45.5; b=10.0;
sum=a+b; diff=a-b; prod= a*b; qt=a/b ;
[Link](“Sum=”+sum);
[Link](“difference=”+diff);
[Link](“Product=”+prod);
[Link](“Quotient=”+qt);
}
}
[Link] to assign value of a=21,b=11,c=7. calculate and print result of an equation(s=7a3+5b2+6c).
class Calc
{
public static void main()
{
double a,b,c,s;
a=21;
b=11;
c=7;
sum=7*a*a*a+5*b*b+6*c;
[Link](“Result=”+s);
}
}
[Link] to assign marks of a student in comp=70.5, math= 79.5,phy=75,chem=72. Calculate and print total mark,average mark .
.
class Student
{
public static void main()
{
double avg,tot ,comp,math,phy,chem;
comp=70.5; math=79.5; phy=75.0;
chem=72.0;
tot= comp+math+phy+chem;
avg=tot/4.0;
[Link](“Total mark=”+tot);
[Link](“Average mark”+avg);
}
}