You are on page 1of 56

Sr.

No Program
1 W.A P. to print Simple String in java
2 W.A P. to perform All operations in
Java
3 W.A P. to we may perform All
operations in Java by using
command line argument
4 W.A P. to find the Area of Circle in
java
5 W.A.P. to find the Percentage of any
class
6 W.A P. to print any No. of Table
7 W. A P. to find the greatest
between three Number
8 W. A P. to given no 1 then print
“One”and 2 then print “Two” by
using switch case
9 W. A P. to Sum of two no by using
Simple & Single inheritance
10 W. A P. to Sum of two no by using
Multilevel inheritance
11 W. A P. to perform two operations
by using Hierarchical inheritance
12 W. A P. to Sum of two no in Simple
& Single inheritance and by using
command line argument
13 W. A P. to Sum of two no in
Parameterized constructor
14 W. A P. to sum of two no by using
default constructor
15 W. A P. to all operation perform in
Constructor overloading
16 W. A P. to show the method No
argument and no return
17 W. A P. to show the method with
argument no return
18 W. A P. to show the method with
argument and with return
19 W. A P. to show the method No
argument and with return
20 W. A P. show the Method
Overloading with help of command
line argument
21 W. A P. show the method overriding
22 W. A P. to the two Number Addition
and Division with the help of Super
keyword
23 W. A P. to Sum of to no in interface
program
24 W. A P. to Show the Exception
handling
25 W. A P. to input Age of preson and
find he can vote or not by using
command line argument
Program -1

# Write a program to print Simple String in java


class simple
{
public static void main(String[] args)
{
System.out.println(" \n ****** Welcome to Jamuna
Prasad Memorial College Bareilly ******* ");
}
}
Output:-
Program-2

# Write a program we may perform All operations in Java

Class alloperations
{
public static void main(String[] args)
{
int a=10,b=20,c,m,d,s;
c=a+b;
m=a*b;
d=a/b;
s=a-b;
System.out.println(" \n sum= "+c);
System.out.println(" \n multiply= "+m);
System.out.println(" \n devision= "+d);
System.out.println(" \n subtract= "+s);
}
}
Output :-
Program-3

# Write a program we may perform All operations in Java with


the help of Command line argument

class commandline
{
public static void main(String[] args)
{
float a,b,s,m,d,s1;
a=Float.parseFloat(args[0]);
b=Float.parseFloat(args[1]);
s=a+b;
m=a*b;
s1=a-b;
d=a/b;
System.out.println("\n Sum="+s);
System.out.println("\n Munltiply="+m);
System.out.println("\n Subtract="+s1);
System.out.println("\n Devision="+d);
}
}
Output :-
Program-4

# Writ a program to find the Area of Circle in java


class area
{
public static void main(String[] args)
{
Float r,b,a;
r=Float.parseFloat(args[0]);
b=Float.parseFloat(args[1]);
a=r*r*b;
System.out.println(" \n Area of Circle = "+a);
}
}
Output:-
Program-5

# Writ a program to find the Percentage of any class with the


help of command line argument in java.
Class percentage
{
public static void main(String[] args)
{
int h,e,p,c,m,t,pr;
h=Integer.parseInt(args[0]);
e=Integer.parseInt(args[1]);
p=Integer.parseInt(args[2]);
c=Integer.parseInt(args[3]);
m=Integer.parseInt(args[4]);
t=h+e+p+c+m;
pr=(h+e+p+c+m)*100/500;
System.out.println("Total Numbers in Inter Class =
"+t);
System.out.println("Total Persentage in Inter Class =
"+p);
}
}
Outout;-

Program -6
# -Write a program to print any No. of Table with the help of
command line argument in java
class table2
{
public static void main(String[] args)
{
int a,i,t;
a=Integer.parseInt(args[0]);
for(i=1;i<=10;i++)
{
t=a*i;
System.out.println(a +"*" +i + "=" +t);
}
}
}
Program-12

#-Write a program to find the greatest between three no in java

class good1
{
public static void main(String[] args)
{
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[0]);
c=Integer.parseInt(args[0]);
int a=22,b=12,c=32;

if(a>b&a>c)
{
System.out.println(" a no is grates ="+a);
}
if(b>a&b>c)
{
System.out.println(" b no is greatest ="+b);
}
if(c>a&c>b)
{
System.out.println(" c no is greatest = "+c);
}
}
}
Output:-
Program-13

# - Write a program given no 1 then print “One ”and 2 then pint


“Two” by using switch case in java

class hello1
{
public static void main(String[] args)
{
int a,b,c;
a=Integer.parseInt(args[0]);
switch ( a)
{
case 1:System.out.println(" One \n");break;
case 2:System.out.println(" Two \n");break;
case 3:System.out.println(" Three \n");break;

}
}
}
Output:-
Program-14

#-Write a program Sum of two no by using Simple & Single


inheritance in java

class base
{
int a=10;

}
class drived extends base
{
int b=20,c;
void sum()
{
c=a+b;
System.out.println(" \n sum="+c);
}
}
class inh1
{
public static void main(String[] args)
{
drived d=new drived();
d.sum();
}
}
Output:-
Program-15

#-Write a program Sum of two no by using Multilevel


inheritance in java

class base
{
int a=10;

}
class base2 extends base
{
int x=12,m;
}
class drived extends base2
{
int b=20,c;
void sum()
{
c=a+b*x;
System.out.println(" \n sum="+c);
}
}
class inh2
{
public static void main(String[] args)
{
drived d=new drived();
d.sum(); }
}
Output:-
Program-16

#-Write a program to we may perform two operations by using


Hierarchical inheritance in java

class base
{
int a=20;

}
class base2 extends base
{
int x=12,m;
void mult()
{
m=a*x;
System.out.println(" \n multiply="+m);
}
}
class drived extends base2
{
int b=35,c;
void sum()
{
c=a+b;
System.out.println(" \n sum="+c);
}
}
class inh3
{
public static void main(String[] args)
{
base2 b=new base2();
b.mult();

drived d=new drived();


d.sum();
}
}

Output:-
Program-17

#-Write a program Sum of two no by using Simple & Single


inheritance and with the help f command line argument in java

class hello
{
int a;
}
class good extends hello
{
int b,c;
void sum()
{
c=a+b;

System.out.println(" sum="+c);

}
}
class inhco
{
public static void main(String[] args)
{

hello h=new hello();


good o=new good();
o.a=Integer.parseInt(args[0]);
o.b=Integer.parseInt(args[1]);
o.sum();

}
}

Output:-
Program-18

#-Write a program two no addition Parameterized constructor

class hello
{
int a,b,c;
hello(int x,int y)
{
a=x;
b=y;
}
void sum()
{
c=a+b;
System.out.println(" Sum= "+c);
}
}
class good1
{
public static void main(String[] args)
{
hello h=new hello(3,6);
h.sum();
}
}

Output:-
Program-19

#-Write a program sum of two no by using default constructor


in java

class hello
{
int a,b,c;
hello()
{
a=10;
b=20;
}

void sum()
{
c=a+b;
System.out.println(" \n Sum="+c);
}
}
class good
{
public static void main(String[] args)
{
hello h=new hello();
h.sum();

}
}
Output:-

Program-20

#-Write a program all operation perform in Constructor


overloading

class hello
{
float a,b,c;
hello(float k,float l )
{
a=k;
b=l;
}
void sum()
{
c=a+b;

System.out.println("\n Sum= "+c);


}
void sub()
{
c=a-b;
System.out.println("\n Sub= "+c);
}
void multi()
{
c=a*b;
System.out.println("\n Multiply= "+c);
}
void devi()
{
c=a/b;
System.out.println("\n Division= "+c);
}
}
class good2
{
public static void main(String[] args)
{
hello h=new hello(14,10);
h.sum();
h.sub();
h.multi();
h.devi();
}
}
Output:-
Project-21

#- Write a program to show the method No argument and no


return

class hello
{
int a=10,b=20,c;
void sum()
{
c=a+b;
System.out.println(" \n Sum="+c);
}
}
class sum
{
public static void main(String[] args)
{
hello h=new hello();
h.sum();
}
}
Output:-
Project-22

#-Write a program to show the method with argument no


return
class hello
{
int a,b,c;
void sum( int a,int b)
{
c= a+b;
System.out.println(" \n Sum="+c);
}
}
class sum2
{
public static void main(String[] args)
{
hello h=new hello();
h.sum(20,30);
}
}

Output:-
Project-23

#-Write a program to show the method with argument and


with return
class hello
{
int a,b,c;
int sum( int a,int b)
{
c= a+b;
return (c);
}
}
class sum3
{
public static void main(String[] args)
{
int s;
hello h=new hello();
s=h.sum(20,30);
System.out.println("\n Sum="+s);

}
}
Output:-

Project-23

#-Write a program show the method No argument and with


return
class hello
{
int a=10,b=20,c;
int sum()
{
c=a+b;
return (c);
}
}
class sum1
{
public static void main(String[] args)
{
hello o=new hello();
int s;
s=o.sum();
System.out.println(" \n Sum="+s);
}
}
Output:-
Projetc-25

#-Write a program show the Method Overloading with help of


command line argument
class hello
{
int a=20,b=30,c,x,y,z;
void sum()
{
c=a+b;
System.out.println(" \n Sum = a+b = "+c);
}
void mult(int x,int y)
{
z=x*y;
System.out.println(" \n Multiply = x*y= "+z);
}

}
class over
{
public static void main(String[] args)
{
hello o=new hello();
o.sum();
o.mult(10,29); }
}
Output:-

Project-26

#-Write a program show the method overriding

class hello
{
int a,b,c,x,y,z;
void sum(int a,int b)
{
c=a+b;
System.out.println(" \n Sum =a+b="+c);
}
void sub(int x,int y)
{
z=x+y;
System.out.println(" \n Subtraction=x+y="+z);
}
}
class overr
{
public static void main(String[] args)
{
hello h=new hello();
h.sum(20,10);
h.sub(20,5);
}
}
Output:-

Project-27

#-Write a program to the two Number Addition and Division


with the help of Super keyword

class hello
{
int a=20,b=3;
}
class drive extends hello
{
int a=10,b=27,c,d;
void sum()
{
c=a+super.a;
System.out.println(" \n Sum= a+a.super="+c);
}
void div()
{
d=b/super.b;
System.out.println(" \n Devision=
b/super.b="+d);
}
}
class main
{
public static void main(String[] args)
{
drive d=new drive();
d.sum();
d.div();
}

}
Output:-
Project-28

#-Write a program to all operation perform in interface


program with the help of command line argument
interface hello
{
int a=20,b=34;
}
class main implements hello
{
int s;
void sum()
{
s=a+b;
System.out.println(" \n Sum= a+b ="+s);
}

}
class inter
{
public static void main(String[]arg)
{
hello h;
main n=new main();
h=n;
n.sum();
}
}
Output:-
Program=29

#- Write a program to show the exception handling

class excep
{
public static void main(String[] args)
{
int a=2,b=0,c;
try
{
c=a/b;
System.out.println("Result="+c);
}
catch (ArithmeticException o)
{
System.out.println(" \n No can not devide by
zero");
}

}
}

Output:-
Program-30
#- Write a program to input Age of person and find he can vote
or not by using command line argument

class vote
{
public static void main(String[] args)
{
int a;
a=Integer.parseInt(args[0]);
if(a>18)
{
System.out.println(" \n He can Vote "+a);
}
if (a<18)
{
System.out.println(" \n He can't Vpte "+a);
}
}
}

Output:-

You might also like