Simple code to find determinants of a 2x2 array using Java
import java.util.Scanner;
public class ex {
public static void main(String[]args) {
System.out.print("\f");
int a[][] = new int[2][2];
int result;
Scanner sc=new Scanner(System.in);
for(int i =0;i<2;i++)
{
for(int j =0;j<2;j++)
{
System.out.print("-Enter value of Index ["+ i +"]["+ j+"] : ");
int val=sc.nextInt();
a[i][j]=val;
}
}
result=(a[0][0]*a[1][1])-(a[0][1]*a[1][0]);
System.out.println("Answer is : "+result);
}
}
تعليقات
إرسال تعليق