// we can not find the mistke in this code.. that was a simple code but we are a
ID: 3636874 • Letter: #
Question
// we can not find the mistke in this code.. that was a simple code but we are amking a mistake in the class, i think.. can you give the correct form of this code.
public class pascal
{
public static void main( String[] args)
{
int a1,a1,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4;
int [] [] c = new int [2] [2] ;
a = new int [2] [2] ;
b = new int [2] [2] ;
System.out.print ("please give the first maatris: ") ;
a1 = scan.nextInt ();
a2 = scan.nextInt ();
a3 = scan.nextInt ();
a4 = scan.nextInt ();
System.out.print ("please give the second matris: ") ;
b1 = scan.nextInt ();
b2 = scan.nextInt ();
b3 = scan.nextInt ();
b4 = scan.nextInt ();
int [][] a = {{a1,a2},
{a3,a4} };
int [][] b = {{b1,b2},
{b3,b4} };
multiply (a , b ) = c ;
System.out.print ("here you go: " +c ) ;
public static int [][] multiply ( int [][]a , int [][] b ) {
( a [0][0] ) * ( b[0][0] ) + ( a [0][1] ) * ( b[1][0] ) = c1 ;
( a [0][0] ) * ( b[0][1] ) + ( a [0][1] ) * ( b[1][1] ) = c2 ;
( a [1][0] ) * ( b[0][0] ) + ( a [1][1] ) * ( b[1][0] ) = c3 ;
( a [1][0] ) * ( b[0][1] ) + ( a [1][1] ) * ( b[1][1] ) = c4 ;
c = new int [2] [2] ;
int [][] c = {{c1,c2},
{c3,c4}
} ;
return c ;
}
}
}
// end of class pascal
Explanation / Answer
HERE!! This is the fixed java code. It works, i tested it out.
import java.util.Scanner;
public class Matrix
{
public static void main( String[] args)
{
int a1,a2,a3,a4,b1,b2,b3,b4;
int [] [] c = new int [2] [2] ;
System.out.print ("please give the first matrix: ") ;
Scanner scan = new Scanner(System.in);
a1 = scan.nextInt ();
a2 = scan.nextInt ();
a3 = scan.nextInt ();
a4 = scan.nextInt ();
System.out.print ("please give the second matrix: ") ;
b1 = scan.nextInt ();
b2 = scan.nextInt ();
b3 = scan.nextInt ();
b4 = scan.nextInt ();
int [][] a = {{a1,a2},
{a3,a4} };
int [][] b = {{b1,b2},
{b3,b4} };
c = multiply (a , b );
System.out.print ("here you go: " + " [" + c[0][0] + " " + c[0][1] + "] "+ "[ " + c[1][0] + " " + c[1][1] + "] ") ;
}
public static int [][] multiply ( int [][]a , int [][] b ) {
int c1 = ( a [0][0] ) * ( b[0][0] ) + ( a [0][1] ) * ( b[1][0] );
int c2 = ( a [0][0] ) * ( b[0][1] ) + ( a [0][1] ) * ( b[1][1] );
int c3 = ( a [1][0] ) * ( b[0][0] ) + ( a [1][1] ) * ( b[1][0] );
int c4 = ( a [1][0] ) * ( b[0][1] ) + ( a [1][1] ) * ( b[1][1] );
int[][] c = {{c1,c2},{c3,c4}};
return c ;
}
}
// end of class pascal
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.