Q. Write a java program to accept the two integer values and Multiply them dynamically .
Program:-
class Mul
{
int a,b,c;
void accept(int p,int q)
{
a=p;
b=q;
}
void multiply()
{
c=a*b;
}
void display()
{
System.out.println("value of a ="+a);
System.out.println("value of b ="+b);
System.out.println("Multiply ="+c);
}
}
class MulDemo
{
public static void main(String k[])
{
if(k.length!=2)
{
Sysetm.out.println("Please Enter the 2 values");
}
else
{
int x=Integer.parseInt(k[0]);
int x1=Integer.parseInt(k[1]);
Mul m= new Mul();
m.accept(x,x1);
m.multiply();
m.display();
}
}
}
{
int a,b,c;
void accept(int p,int q)
{
a=p;
b=q;
}
void multiply()
{
c=a*b;
}
void display()
{
System.out.println("value of a ="+a);
System.out.println("value of b ="+b);
System.out.println("Multiply ="+c);
}
}
class MulDemo
{
public static void main(String k[])
{
if(k.length!=2)
{
Sysetm.out.println("Please Enter the 2 values");
}
else
{
int x=Integer.parseInt(k[0]);
int x1=Integer.parseInt(k[1]);
Mul m= new Mul();
m.accept(x,x1);
m.multiply();
m.display();
}
}
}
Q. Write a java program to accept the integer values and square them dynamically .
Program:-
class Square
{
int n,res;
void accept(int x)
{
n=x;
}
void calSquare()
{
res=n*n;
}
void display()
{
System.out.println("value of n="+n);
System.out.println("Square="+res);
}
}
class SquareDemo
{
public static void main(String k[])
{
if(k.length!=1)
{
System.out.println("Please Enter the one Value");
}
else
{
int x=Integer.parseInt(k[0]);
Square s=new Square();
s.accept(x);
s.calSquare();
s.display();
}
}
}
Q. Write a java program to accept the two values and find the Area Of Triangle dynamically.
Program:-
class Triangle
{
float b,,h,res;
void accept(float x,float y)
{
b=x;
h=y;
}
void area()
{
res=0.5*b*h;
}
void display()
{
System.out.println("value of b="+b);
System.out.println("value of h="+h);
System.out.println("AreaOfTRaingle="+res);
}
}
class TraingleDemo
{
public static void main(String k[])
{
if(k.length!=2)
{
System.out.println("Please Enter the two Value");
}
else
{
float x1=Float.parseFloat(k[0]);
float x2=Float.parseFloat(k[1]);
Triangle t=new Triangle();
s.accept(x1,x2);
s.area();
s.display();
}
}
}
Q. Write a java program to accept the two integer values and swapping them dynamically .
program:-
class Swap
{
int a,b,t,;
void accept(int p,int q)
{
a=p;
b=q;
}
void swapValues()
{
t=a;
a=b;
b=a;
}
void display()
{
System.out.println("values of a="+a);
System.out.println("values of b="+b);]
}
}
class SwapDemo
{
public static void main(String k[])
{
if (k.length!=2)
{
System.out.println("Please Enter Two values");
}
else
{
int x1=Integer.parseInt(k[0]);
int x2=Integer.parseInt(k[1]);
Swap s=new Swap(); //create an Object of swap class
s.accept(x1,x2); //swaping of two values
s.swapValues();
s.display();
}
}
}
{
int a,b,t,;
void accept(int p,int q)
{
a=p;
b=q;
}
void swapValues()
{
t=a;
a=b;
b=a;
}
void display()
{
System.out.println("values of a="+a);
System.out.println("values of b="+b);]
}
}
class SwapDemo
{
public static void main(String k[])
{
if (k.length!=2)
{
System.out.println("Please Enter Two values");
}
else
{
int x1=Integer.parseInt(k[0]);
int x2=Integer.parseInt(k[1]);
Swap s=new Swap(); //create an Object of swap class
s.accept(x1,x2); //swaping of two values
s.swapValues();
s.display();
}
}
}
Output:-
cd/
cd blog data
javac SwapDemo.java
java SwapDemo 10 20
cd/
cd blog data
javac SwapDemo.java
java SwapDemo 10 20
Q. Write a java program to accept two values and find Big value with the dynamically .
Program:-
class Big
{
int a,b;
void set(int x,int y)
{
a=x;
b=y;
}
void findBig()
{
if(a==b)
{
System.out.println("Both values are same");
}
else
{
if (a>b)
{
System.out.println(a+" is greater than"+ b);
}
else
{
System.out.println(b+"is greater than"+a);
}
}
}
}
class BigDemo
{
public static void main(String k[])
{
if (k.length!=2)
{
System.out.println("Please Enter the 2 values");
}
else
{
int x1=Integer.parseInt(k[0]);
int x2=Integer.parseInt(k[1]);
Big b=new Big();
b.set(x1,x2);
b.findBig();
}
}
}
class Big
{
int a,b;
void set(int x,int y)
{
a=x;
b=y;
}
void findBig()
{
if(a==b)
{
System.out.println("Both values are same");
}
else
{
if (a>b)
{
System.out.println(a+" is greater than"+ b);
}
else
{
System.out.println(b+"is greater than"+a);
}
}
}
}
class BigDemo
{
public static void main(String k[])
{
if (k.length!=2)
{
System.out.println("Please Enter the 2 values");
}
else
{
int x1=Integer.parseInt(k[0]);
int x2=Integer.parseInt(k[1]);
Big b=new Big();
b.set(x1,x2);
b.findBig();
}
}
}
Q. Write a java program to accept two values and find the Biggest value with the dynamically .
Program:-
class Biggest
{
int a,b,c;
void set(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
void findBiggestValue()
{
if (a>0 && a>b && a>c)
{
System.out.println(a+" is bigger ");
}
if (b>0 && b>c && b>a)
{
System.out.println(b+" is bigger ");
}
if (c>0 && c>b && c>a)
{
System.out.println(c+" is bigger");
}
else
{
System.out.println("Both values are same");
}
}
}
class BiggestDemo
{
public static void main(String k[])
{
if (k.length!=3)
{
System.out.println("Please Enter the 3 values");
}
else
{
int x1=Integer.parseInt(k[0]);
int x2=Integer.parseInt(k[1]);
int x3=Integer.parseInt(k[2]);
Biggest b=new Biggest();
b.set(x1,x2,x3);
b.findBiggestValue();
}
}
}
{
int a,b,c;
void set(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
void findBiggestValue()
{
if (a>0 && a>b && a>c)
{
System.out.println(a+" is bigger ");
}
if (b>0 && b>c && b>a)
{
System.out.println(b+" is bigger ");
}
if (c>0 && c>b && c>a)
{
System.out.println(c+" is bigger");
}
else
{
System.out.println("Both values are same");
}
}
}
class BiggestDemo
{
public static void main(String k[])
{
if (k.length!=3)
{
System.out.println("Please Enter the 3 values");
}
else
{
int x1=Integer.parseInt(k[0]);
int x2=Integer.parseInt(k[1]);
int x3=Integer.parseInt(k[2]);
Biggest b=new Biggest();
b.set(x1,x2,x3);
b.findBiggestValue();
}
}
}
Q. Write a java program which will accept the numerical integer values fin that whether it is Positive Number are not?.
Program:-
class PositiveNumber
{
int n;
void set(int x)
{
n=x;
}
void decide()
{
if (n>0)
{
System.out.println(n+"is positive");
}
else
{
System.out.println(n+"is negative");
}
}
}
class PositiveNumberDemo
{
public static void main(String[] k)
{
if (k.length!=1)
{
System.out.println("Please Enter the one value");
}
else
{
int x1=Integer.parseInt(k[0]);
PositiveNumber po=new PositiveNumber();
po.set(x1);
po.decide();
}
}
}
Q. Write a java Program which will accept the numerical values and find that whether it is Even Or Odd numbers?.
Program:-
class EvenOdd
{
int a;
void set(int x)
{
a=x;
}
void decide()
{
if (a<=0)
{
System.out.println("Enter The Positive Number");
}
else
{
if (a%2==0)
{
System.out.println(a+"Even Number");
}
else
{
System.out.println(a+"Odd Number");
}
}
}
}
class EvenOddDemo
{
public static void main(String[] k)
{
if (k.length!=1)
{
System.out.println("Please Enter the one value");
}
else
{
int x1=Integer.parseInt(k[0]);
EvenOdd e=new EvenOdd();
e.set(x1);
e.decide();
}
}
}
{
int n;
void set(int x)
{
n=x;
}
void decide()
{
if (n>0)
{
System.out.println(n+"is positive");
}
else
{
System.out.println(n+"is negative");
}
}
}
class PositiveNumberDemo
{
public static void main(String[] k)
{
if (k.length!=1)
{
System.out.println("Please Enter the one value");
}
else
{
int x1=Integer.parseInt(k[0]);
PositiveNumber po=new PositiveNumber();
po.set(x1);
po.decide();
}
}
}
Q. Write a java Program which will accept the numerical values and find that whether it is Even Or Odd numbers?.
Program:-
class EvenOdd
{
int a;
void set(int x)
{
a=x;
}
void decide()
{
if (a<=0)
{
System.out.println("Enter The Positive Number");
}
else
{
if (a%2==0)
{
System.out.println(a+"Even Number");
}
else
{
System.out.println(a+"Odd Number");
}
}
}
}
class EvenOddDemo
{
public static void main(String[] k)
{
if (k.length!=1)
{
System.out.println("Please Enter the one value");
}
else
{
int x1=Integer.parseInt(k[0]);
EvenOdd e=new EvenOdd();
e.set(x1);
e.decide();
}
}
}
No comments:
Post a Comment
Thanks for visiting my site..