Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java question! Class WrongLength {public String FormatError () {return \"error\"

ID: 3575601 • Letter: J

Question

java question!

Class WrongLength {public String FormatError () {return "error"}} A. What is wrong with this code for defining an exception? B. This Exception isn't very useful, in order to bolster it's usefulness, add three fields, one String and two ints. Change the exception to accept these fields. C. Here is a method: get Matrix (int [] [] mat) {if (mat [0]. length ! = mat. length ()) {//Throw an exception} else {Sick computations}} Your job is to change the method, and also the exception. The method must throw your exception when a matrix isn't square, and the method must return a string that states the size of each dimension of tin; array. Assume an array is passed in with greater than 0, 0 for dimensions.

Explanation / Answer

1. Syntax error, semicolon is expected.

2. Try this code

import java.util.Scanner;
public class ErrorClass{
public static void main(String []args)
{
System.out.println(" Enter a value : ");
Scanner in = new Scanner(System.in);
int a = in.nextInt();
getMatrix(a);
}
public void getMatrix(int[][] mat)
{
if(mat[0].length!=mat.length())
{
String error = "Error";
return error;
}
else
System.out.println("sick computations");
}

}