Last active
August 11, 2020 09:06
-
-
Save AakashCode12/a651bbc50ce0f78a6de3b9d5bb13cbd1 to your computer and use it in GitHub Desktop.
The practical -4 | OOPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class onedarray{ | |
public static void main(String args[]){ | |
Scanner sc = new Scanner(System.in); | |
int arr[]=new int[5]; | |
for(int i=0;i<5;i++){ | |
arr[i]=sc.nextInt(); | |
} | |
//sorting program | |
int temp; | |
for(int i=0;i<5;i++){ | |
for(int j=0;j<5;j++){ | |
if(arr[i]>arr[j]){ | |
temp=arr[i]; | |
arr[i]=arr[j]; | |
arr[j]=temp; | |
} | |
} | |
} | |
//print the array which we sorted | |
for(int i=0;i<5;i++){ | |
System.out.println(arr[i]); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class twodarray{ | |
public static void main(String args[]){ | |
Scanner sc = new Scanner(System.in); | |
int matrix1[][]=new int[2][2]; | |
int matrix2[][]=new int[2][2]; | |
System.out.println("enter the first matrix"); | |
//Input for matrix 1 | |
for(int i=0;i<2;i++){ | |
for(int j=0;j<2;j++){ | |
matrix1[i][j]=sc.nextInt(); | |
} | |
} | |
System.out.println("enter the second matrix"); | |
//Input for matrix 2 | |
for(int i=0;i<2;i++){ | |
for(int j=0;j<2;j++){ | |
matrix2[i][j]=sc.nextInt(); | |
} | |
} | |
//addition of two matrices | |
for(int i=0;i<2;i++){ | |
for(int j=0;j<2;j++){ | |
matrix1[i][j]=matrix1[i][j]+matrix2[i][j]; | |
} | |
} | |
System.out.println("The ans is"); | |
//print the answer | |
for(int i=0;i<2;i++){ | |
for(int j=0;j<2;j++){ | |
System.out.print(matrix1[i][j]+" "); | |
} | |
System.out.println(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PointCoordinates{ | |
private int x,y; | |
public int add(int x,int y){ | |
this.x=x; | |
this.y=y; | |
return x+y; | |
} | |
public int getX(){ | |
return x; | |
} | |
public int getY(){ | |
return y; | |
} | |
} | |
class thisfunction{ | |
public static void main(String args[]){ | |
PointCoordinates obj = new PointCoordinates(); | |
int sum= obj.add(1,2); | |
int m=obj.getX(); | |
int n=obj.getY(); | |
System.out.println(sum); | |
System.out.println(m); | |
System.out.println(n); | |
System.out.println(obj); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment