Академический Документы
Профессиональный Документы
Культура Документы
CLASS ADD2DARRAY
{
ADD2DARRAY()
{
INT[] A={{1,2,3}{1,2,3}};
INT[] B={{4,5,6},{7,8,9}};
INT C[]=NEW INT[2][2];
for(int i=0;i<rows;i++)
{
for(int j=0;j<col;j++)
{
int c[i][j]=a[i][j]+b[i][j]
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
System.out.priint("addition of array:"+c[i][j]);
}
}
}
}
PUBLIC STATIC VOID MAIN(string[] args)
{
ADD2DARRAY T=NEW ADD2DARRAY ();
CLASS SORTARRAY
{
SORTARRAY()
{
int[] arr={2,1,3,4,10,9,8};
int temp=0;
for(int i=0;i<arr.length;i++)
{
for(int j=i+1;j<arr.length;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println(":"+arrays.tostring(a));
}
}
CLASS ARRSORT
{
PUBLIC STATIC VOI MAIN(STRING[] ARGS)
{
SORTARRASY S=NEW SORTARRASY();
}
}
CLASS STRINGARRAYS
{
STRINGARRAYS()
{
string s[]={"d","e","v","u","r","a","m"};
int temp=0;
for(int i=0;i<s.length;i++)
{
for(int j=i+1;j<s.length;j++)
{
if(s[i].compareto(str[j])<0)
{
tmp=s[i];
s[i]=s[j];
s[j]=temp;
}
system.out.println(":"+s[i]);
}
}
}
CLASS MAINSTRING()
{
public static void main(String[] args)
{
MAINSTRING M=NEW MAINSTRING();
}
}
Q4)WRITE A CONSTRUCTOR TO MULTIPLICATION 2D ARRAY?
class MultidimensionArray
{
MultidimensionArray()
{
int m1[][]={{1,2,3},{4,5,6}};
int m2[][]={{7,8},{9,10},{11,12}};
}
r[i][j]=sum;
sum=0;
}
}
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.print(r[i][j]+" ");
}
System.out.println();
}
}
}
CLASS MAINMULTIARRAYS
{
PUBLIC STATIC VOID MAIN(sTRING[] ARGS )
MultidimensionArray M=NEW MultidimensionArray ();
class CONSTRUCORARRAY
{
CONSTRUCORARRAY()
{
int a[]={2,3,5,2,7,8};
int b[]=new int[6];
int n=a.length;
for(int i=0;i<n;i++)
{
b[i]=a[i];
System.out.print(b[i]+" ");
}
} }
CLASS MAINARRAY
{
PUBLIC STATIC VOID MAIN(STRING[] ARGS)
{
CONSTRUCORARRAY C=NEW CONSTRUCORARRAY();
}
}
package constructors;
One1Dto2DArray()
{
int[] a= {1,2,3,4,5,6};
int[][] b=new int[2][3];
int k=0;
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
b[i][j]=a[k];
System.out.print(" " +b[i][j]);
k++;
}
System.out.println();
}
package constructors;
System.out.print(" "+b[i]);
}
}
}
public static void main(String[] args)
{
TwoDtoOneD t=new TwoDtoOneD();
class Stringpresent {
Stringpresent (){
}
class Mainstring
{
public static void main(String[] args)
{
Stringpresent S=NEW Stringpresent ();
}
}
CLASS BIGGERNO
{
BIGGERNO()
{
INT A=10;
INT B=5;
INT BIGVALUE;
IF(A>B)
{
BIGVALUE=A;
}
ELSE
{
BIGVALUE=B;
}
}
}
CLASS BIGGERVALUE
{
PUBLIC STATIC VOID MAIN(STRING[] ARGS)
{
BIGGERNO B=NEW BIGGERNO();
}
}
EX:INT ARR[]={1,5,7,9,10}
CLASS SORTARRAY
{
SORTARRAY()
{
int[] arr={1,5,7,9,10};
int temp=0;
for(int i=0;i<arr.length;i++)
{
for(int j=i+1;j<arr.length;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println(":"+arrays.tostring(a));
}
}
CLASS ARRSORT
{
PUBLIC STATIC VOI MAIN(STRING[] ARGS)
{
SORTARRASY S=NEW SORTARRASY();
}
}
CLASS SAMEARRAY
{
SAMEARRAY()
{
int[] arr1 = new int [] {1,3,4,7,9};
int[] arr2 = new int [] {2,5,6,8,10};
if(arr1==arr2)
System.out.println("equal arrays");
else
System.out.println("not equal");
}
class ArraysEqual
{
public static void main(String[] args)
{
SAMEARRAY s=new SAMEARRAY();
}
}
class Arrayslength
{
public static void main(string[] args)
{
int[] arr={1,2,3,4,5,6};
int i=0;
for(int arrays:arr)
{
i++;
}
system.out.println("arrays of length:"+i);
}
}
}
}
*They don't have return type, not even void and hence can't return any values.
*They can't be inherited; through a derived class, can call the base class
constructor.
*elements of different objects with different values when they are created.
*when object the class is created , its constructor is called first (default
constructor)
by the JVM.
ex:-
class myclass
{
MYCLASS()
{
SYSTEM.OUT.PRINTLN("CONSTRUCTOR");
}
}
CLASS MYCONSTRUCTOR
{
public static void main(string []args)
{
MYCLASS m=new MYCLASS();
}
}