Вы находитесь на странице: 1из 36

Roll No.: Date: ...

.. Page No.: .. Practical Name: ...


.... Practical No.: .

import java.util.Scanner;

class quad

{
public static void main(String args[])
{
System.out.println("NAME : SHUBHANSHU SINGH");
System.out.println("UNIVERSITY ROLL NUMBER :
1503213104"); int a,b,c,d;
double x=0,y=0;
System.out.println("enter the coefficients of quadratic equation");
Scanner in = new Scanner(System.in);
a=in.nextInt();
b=in.nextInt();
c=in.nextInt(
); d=(b*b)(4*a*c);
if(d>=0)
{
if(d>0)
{
System.out.println("roots are real and
distinct"); x=(Math.sqrt(d)-b)/(2*a);
y=-(Math.sqrt(d)+b)/(2*a);
}
else if(d==0)
{
System.out.println("roots are real and equal");

ABES Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

x=-(b(2*a));
y=x;
}
System.out.println("x1="+x);
System.out.println("x2="+y);
}
else
{
System.out.println("there are no real solutions");
}
}
}

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

import java.util.Scanner;

class fib
{
public static void main(String args[])
{
System.out.println("NAME : SHUBHANSHU SINGH");
System.out.println("UNIVERSITY ROLL NUMBER :
1503213104"); int a=0,b=1,c=0,n;
System.out.println("enter the
value of n"); Scanner in=new
Scanner(System.in);
n=in.nextInt();
n=n-2;
while(n
>0)
{
c=a+b;
a=b;
b=
c;
n--;
}
System.out.println("nth value of fibonacci sequence is "+c);
}
}

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

import java.util.Scanner;

class fibo
{
public static void main(String args[])
{
System.out.println("NAME : SHUBHANSHU SINGH");
System.out.println("UNIVERSITY ROLL NUMBER :
1503213104"); int n,f=0;
System.out.println("enter the
value of n"); Scanner in=new
Scanner(System.in);
n=in.nextInt();
f=fibonacci(n);
System.out.println("nth value of fibonacci sequence is "+f);
}
public static int fibonacci(int x)
{
if(x==1)
return 0;
else
if(x==2)
return 1;
else

return fibonacci(x-1)+fibonacci(x-2);
}
}

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

import java.util.Scanner;

class prime
{
public static void main(String args[])
{
System.out.println("NAME : SHUBHANSHU SINGH");
System.out.println("UNIVERSITY ROLL NUMBER :
1503213104"); int n,c=0,i,j;
System.out.print("enter the value
of n: "); Scanner in=new
Scanner(System.in);
n=in.nextInt();
System.out.println("First "+n+" prime
numbers are: "); for(i=1;n>0;i++)
{
c=0;
for(j=1;j<i;j++)
if(i%j==0)
c++;
if(c==1)
{
System.out.print("
"+i); n--;
}
}
}
}

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

import java.util.Scanner;

class mat
{
public static void main(String args[])
{
System.out.println("NAME : SHUBHANSHU SINGH");
System.out.println("UNIVERSITY ROLL NUMBER :
1503213104"); int i,j,k;
int
int[2][2];
[]=new
int

a[][]=new
int

b[]

int[2][2];
c[][]=new

int[2][2];

Scanner in=new Scanner(System.in);


System.out.println("enter elements in
first matrix"); for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
a[i][j]=in.nextInt();
System.out.println("");
}
System.out.println("enter elements in
second matrix"); for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
b[i][j]=in.nextInt();
System.out.println
(" ");
}
System.out.println("output matrix is");

ABES Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=0;
for(k=0;k<2;k++)
c[i][j]=c[i][j]+(a[i]
[k]*b[k][j]);
System.out.print("
"+c[i][j]);
}
System.out.println("");
}
}
}

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

class rect
{
public static void main(String arg[])
{
System.out.println("NAME : SHUBHANSHU SINGH");
System.out.println("UNIVERSITY ROLL NUMBER : 1503213104");
Rectangle rect1 = new Rectangle(9,5);
System.out.println("Area1 = " + rect1.getArea());
Rectangle rect2 = new Rectangle(8,4);
System.out.println("Area2 = " + rect2.getArea());
}
}
class Rectangle
{
int
length;
int
breadth;

Rectangle(int length, int breadth)


{
this.length =
length;
this.breadth =
breadth;

int getArea()
{
return length * breadth;
}

ABES Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

class Rectangle
{
int
length;
int
breadth;

Rectangle(int l,int b)
{
length=l;
breadth=b;
}
void Area(int i)
{
int area;
area=length*brea
dth ;

System.out.println("Area "+i+" : "+area);


}
}
class sh
{
public static void main(String args[])
{
System.out.println("NAME : SHUBHANSHU SINGH");
System.out.println("UNIVERSITY ROLL NUMBER : 1503213104");
Rectangle ob1=new Rectangle(6,9);
Rectangle ob2=new
Rectangle(5,4); ob1.Area(1);
ob2.Area(2);
}
}

ABES Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

class thread
{
public static void main (String[] args)
{
System.out.println("NAME : SHUBHANSHU SINGH");
System.out.println("UNIVERSITY ROLL NUMBER : 1503213104");
A ob1=new A();
ob1.run();
B ob2=new
B();
ob2.run();
}
}
class A extends Thread
{
public void run()
{
System.out.println("Hello");
}
}
class B extends Thread
{
public void run()
{
System.out.println("ABES");
}
}

ABES
Engineering
College

Sign of Faculty
with date

Roll No.: Date: ...


.. Page No.: .. Practical Name: ...
.... Practical No.: .

ABES
Engineering
College

Sign of Faculty
with date

Вам также может понравиться