 Object Oriented Programming through JAVA.pptx
Object Oriented Programming through JAVA.pptx Types of variables.pptx
Types of variables.pptx If condition.pptx
If condition.pptx Document from Mahesh Kumar Padmanabhuni
Document from Mahesh Kumar Padmanabhuni Document from Mahesh Kumar Padmanabhuni
Document from Mahesh Kumar Padmanabhuni Document from Mahesh Kumar Padmanabhuni
Document from Mahesh Kumar Padmanabhuni Java - Object and Classes.pptx
Java - Object and Classes.pptx JAVA.pptx
JAVA.pptx Matrices multiplication in java.pptx
Matrices multiplication in java.pptx Document from Mahesh Kumar Padmanabhuni
Document from Mahesh Kumar Padmanabhuni Document from Mahesh Kumar Padmanabhuni
Document from Mahesh Kumar Padmanabhunipublic class DefaultValues
{
byte b;
short s;
int i;
long l;
float f;
double d;
char c;
boolean bl;
public static void main(String[] args)
{
DefaultValues ob = new DefaultValues();
System.out.println("default value of byte is "+ob.b);
System.out.println("default value of short is "+ob.s);
System.out.println("default value of int is "+ob.i);
System.out.println("default value of long is "+ob.l);
System.out.println("default value of float is "+ob.f);
System.out.println("default value of double is "+ob.d);
System.out.println("default value of char is "+ob.c);
System.out.println("default value of boolean is "+ob.bl);
}
}
import java.util.*;
class Lsearch
{
int n;
int a[];
int sr;
Lsearch(int n) // dynamic constructor
{
this.n=n;
a=new int[n];
sr=0;
}
void readData()
{
Scanner s =new Scanner(System.in);
System.out.println("Enter "+n+ "Elements");
for(int i=0;i<n;i++)
a[i]=s.nextInt();
System.out.println("Enter a search element :");
sr=s.nextInt();
}
void search()
{
int f=0;
for(int i=0;i<n;i++)
{
if(a[i]==sr)
f=1;
}
if(f==1)
System.out.println("The element is found ");
else
System.out.println("the element is not found ");
}
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter n value :");
int n=s.nextInt();
Lsearch l=new Lsearch(n);
l.readData();
l.search();
}
}
import java.util.*;
class Racers
{
int n;
int sp[]; //speed
float avg;
void readBikers()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter No of Bikers :");
n=s.nextInt();
sp=new int[n];
int tot=0;
for(int i=0;i<n;i++)
{
System.out.println("Enter the speed of Racer"+(i+1)+" :");
sp[i]=s.nextInt();
tot=tot+sp[i];
}
avg=(float)tot/n;
}
void display()
{
for(int i=0;i<n;i++)
{
if(sp[i]>=avg)
System.out.println("Racer "+(i+1)+"is qualified ");
}
}
public static void main(String args[])
{
Racers r = new Racers();
r.readBikers();
r.display();
}
}
import java.util.Scanner;
class MatrixMultiplication
{
public static void main(String args[])
{
int mat1row, mat1col, mat2row, mat2col,i,j,k,sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows of matrix1");
mat1row = sc.nextInt();
System.out.println("Enter the number columns of matrix 1");
mat1col = sc.nextInt();
System.out.println("Enter the number of rows of matrix2");
mat2row = sc.nextInt();
System.out.println("Enter the number of columns of matrix 2");
mat2col = sc.nextInt();
if(mat1col==mat2row)
{
int mat1[][] = new int[mat1row][mat1col];
int mat2[][] = new int[mat2row][mat2col];
int resMat[][] = new int[mat1row][mat2col];
System.out.println("Enter the elements of matrix1");
for ( i= 0 ; i< mat1row ; i++ )
{
for ( j= 0 ; j < mat1col ;j++ )
{
mat1[i][j] = sc.nextInt();
}
}
System.out.println("Enter the elements of matrix2");
for ( i= 0 ; i< mat2row ; i++ )
{
for ( j= 0 ; j < mat2col ;j++ )
{
mat2[i][j] = sc.nextInt();
}
}
System.out.println("matrix multiplication is ");
for ( i= 0 ; i< mat1row ; i++ )
{
for ( j= 0 ; j <mat2col ; j++)
{
sum=0;
for ( k= 0 ; k <mat2row; k++ )
{
sum +=mat1[i][k]*mat2[k][j] ;
}
resMat[i][j]=sum;
}
}
for ( i= 0 ; i< mat1row; i++ )
{
for ( j=0 ; j < mat2col;j++ )
{
System.out.print(resMat[i][j]+" ");
}
System.out.println();
}
}
else
{
System.out.print("multipication is not possible ");
}
}
}
import java.util.*;
public class Student
{
int rno;//memeber var
String name;
Student() // Deafault
{
System.out.println(" Default Construtor invoked");
rno=0;// s oject
name=" ";
}
Student(int rno,String name)//local varaibles// Parameter
{
System.out.println(" parameter Construtor invoked");
this.rno=rno;//s1.rno=rno;
this.name=name;//s1.name=name;
}
Student(Student sobj)//copy constructor
{
System.out.println(" Copy Construtor invoked");
rno=sobj.rno;// s2.rno=s1.rno;
name=sobj.name;//s2.name=s1.name
}
void putData()
{
System.out.println("Rollno :"+rno);
System.out.println("Name :"+name);
}
public static void main(String[] args)
{
Student s= new Student();// default
Student s1=new Student(102,"RAM");//parameter
Student s2 =new Student(s1);//copy
s.putData();
s1.putData();
s2.putData();
}
}
public class Rectangle
{
int len;
int bre;
Rectangle()
{
len=0;
bre=0;
}
Rectangle(int len,int bre)
{
this.len=len;
this.bre=bre;
}
void area()
{
System.out.println("The area of rectangle is :"+(len*bre));
}
public static void main(String args[])
{
Rectangle r= new Rectangle();// Default constructor
r.area();
Rectangle r1=new Rectangle(3,4);//parameter constructor
r1.area();
}
}
//Program to create class mechanism -cycle 3.1
import java.util.*;
public class Student
{
int rno;//memeber var
String name;
Student()
{
System.out.println("Construtor invoked");
rno=0;
name=" ";
}
void getData()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter Roll no :");
rno=in.nextInt();
System.out.println("Enter Name :");
name=in.next();
}
void putData()
{
System.out.println("Rollno :"+rno);
System.out.println("Name :"+name);
}
public static void main(String[] args)
{
Student s= new Student();
s.getData();
s.putData();
}
}
//class varaiables
//memory allocated first
//are shared all the object
//They are intialized only once
//the values will be changed durig the function call
static datatype variablname;
static int x;
int y;
//memory alloacted first
//they can be called directly
//it will be under the class scope but not object scope
//it can access only static variables but not non static variables
public class staticDemo
{
int x;// non static;
static int y;// static var
staticDemo()// Constructor
{
x=10;
y=20;
}
void displayx()
{
System.out.println("x="+(++x));
}
static void display() // static Method
{
System.out.println("y="+(++y));
}
public static void main(String args[])
{
staticDemo obj1=new staticDemo();
staticDemo obj2=new staticDemo();
staticDemo obj3=new staticDemo();
System.out.println("OBJECT 1 :");
obj1.displayx();
display();
System.out.println("OBJECT 2 :");
obj2.displayx();
display();
System.out.println("OBJECT 3 :");
obj3.displayx();
display();
}
}