in java need both of these methods CS 1180 Lab 10.pdf - Adobe Reader File Edit V
ID: 3684531 • Letter: I
Question
in java need both of these methods
CS 1180 Lab 10.pdf - Adobe Reader File Edit ViewWindow Help Tools Sign Comment Sign In Export PDF 2. Write a method that takes a square two dimensional array of characters and returns true if the characters along the upper left to lower right diagonal are all the same, and false otherwise. For instance, when called like this from main Adobe ExportPDF Convert PDF files to Word or Excel online Select PDF File: char [ ] [ ] array2 = { CS 1180 Lab 10.pdf 1 file/72 KB Convert To: Microsoft Word (.docx) System.out.println("Diagonal check: " + checkDiagonall (array3) the program should display: Diagonal check: true And when called like this Recognize Text in English(U.S.) Change Convert char()I) arEay4 Create PDF Send Files Store Files System.out.println("Diagonal check: "+ checkDiagonall (array4)) the program should display: Diagonal check: falseExplanation / Answer
public class chegg8 {
//checking from upper left to lower right
public static boolean checkul(char [][] arr)
{
int len = arr[0].length;
int cmp = arr[0][0];
for(int i=1;i<len;i++)
{
if(arr[i][i]!=cmp)return false;
}
return true;
}
//Checking from upper right to lower left
public static boolean checkur(char [][] arr)
{
int len = arr[0].length;
int cmp = arr[0][len-1];
for(int i=1;i<len;i++)
{
if(arr[i][len-1-i]!=cmp)return false;
}
return true;
}
public static void main(String args[])
{
char arr[][]={{'c','b','a'},{'d','a','f'},{'a','h','a'}};
boolean c = checkul(arr);
System.out.print("Diagonal check: ");
System.out.println(c);
c = checkur(arr);
System.out.print("Diagonal check: ");
System.out.println(c);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.