SlideShare una empresa de Scribd logo
1 de 2
R. For some array of size, ROW by COLUMN, compute and display the average of the left-to-
right diagonal in java
Solution
import java.util.Scanner;
public class SumOfDiagonals {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int row,column;
System.out.print("Enter row: ");
row = getInt(sc, "");
System.out.print("Enter column: ");
column = getInt(sc, "");
//Declare 2 Dimensional Arrays
int[][] matrix = new int[row][column];
int sum = 0;
// Input Matrix
System.out.println("Enter matrix ");
for (int i = 0; i < row; i++) {
System.out.println("Enter elements of " + i + " row");
for (int j = 0; j < column; j++) {
matrix[i][j] = getInt(sc, "");
}
}
// Compute Sum of main diagonal elements
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
if (i == j) {
sum += matrix[i][j];
}
}
}
int n;
if(row > column) n = column;
else n = row;
System.out.println("Sum of Diagonal Elements is " + sum);
System.out.println("Average of Diagonal Elements is " + sum/n);
}
public static int getInt(Scanner sc, String prompt) {
int integer = 0;
boolean isValid = false;
while (isValid == false) {
System.out.print(prompt);
if (sc.hasNextInt()) {
integer = sc.nextInt();
isValid = true;
} else {
System.err.println("Error! Invalid number. Try again.");
}
sc.nextLine();
}
return integer;
}
}

Más contenido relacionado

Similar a R- For some array of size- ROW by COLUMN- compute and display the aver.docx

ArrayOperations.java import java.util.Arrays; import java.util.pdf
ArrayOperations.java import java.util.Arrays; import java.util.pdfArrayOperations.java import java.util.Arrays; import java.util.pdf
ArrayOperations.java import java.util.Arrays; import java.util.pdfANANDSALESINDIA105
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docxdorisc7
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdfangelsfashion1
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfaniyathikitchen
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfanujsharmaanuj14
 

Similar a R- For some array of size- ROW by COLUMN- compute and display the aver.docx (9)

ArrayOperations.java import java.util.Arrays; import java.util.pdf
ArrayOperations.java import java.util.Arrays; import java.util.pdfArrayOperations.java import java.util.Arrays; import java.util.pdf
ArrayOperations.java import java.util.Arrays; import java.util.pdf
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdf
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
 

Más de diegor62

Introductory Aocounting u 2014 1- Managerial information- accounting m.docx
Introductory Aocounting u 2014 1- Managerial information- accounting m.docxIntroductory Aocounting u 2014 1- Managerial information- accounting m.docx
Introductory Aocounting u 2014 1- Managerial information- accounting m.docxdiegor62
 
Introduction to Java Programming 10th ed --25-4 (Implement preorder t.docx
Introduction to Java Programming 10th ed  --25-4 (Implement preorder t.docxIntroduction to Java Programming 10th ed  --25-4 (Implement preorder t.docx
Introduction to Java Programming 10th ed --25-4 (Implement preorder t.docxdiegor62
 
Indicate the functions of the agent process in a network operating sys.docx
Indicate the functions of the agent process in a network operating sys.docxIndicate the functions of the agent process in a network operating sys.docx
Indicate the functions of the agent process in a network operating sys.docxdiegor62
 
Interpretation 102-4 in the AICPA Code of Professional Conduct calls f.docx
Interpretation 102-4 in the AICPA Code of Professional Conduct calls f.docxInterpretation 102-4 in the AICPA Code of Professional Conduct calls f.docx
Interpretation 102-4 in the AICPA Code of Professional Conduct calls f.docxdiegor62
 
internet domain names are linked to trademark issues- Technology makes.docx
internet domain names are linked to trademark issues- Technology makes.docxinternet domain names are linked to trademark issues- Technology makes.docx
internet domain names are linked to trademark issues- Technology makes.docxdiegor62
 
Internet network management framework as consisting of three major par.docx
Internet network management framework as consisting of three major par.docxInternet network management framework as consisting of three major par.docx
Internet network management framework as consisting of three major par.docxdiegor62
 
Internet Programming ORM This question uses the following two model cl.docx
Internet Programming ORM This question uses the following two model cl.docxInternet Programming ORM This question uses the following two model cl.docx
Internet Programming ORM This question uses the following two model cl.docxdiegor62
 
international ECO 305 course- how does culture embrace globalization a.docx
international ECO 305 course- how does culture embrace globalization a.docxinternational ECO 305 course- how does culture embrace globalization a.docx
international ECO 305 course- how does culture embrace globalization a.docxdiegor62
 
International business is conducted outside of the home country- Natio.docx
International business is conducted outside of the home country- Natio.docxInternational business is conducted outside of the home country- Natio.docx
International business is conducted outside of the home country- Natio.docxdiegor62
 
Intermolecular Interactions Crystalline Solids K14 of 19 Part A Classi.docx
Intermolecular Interactions Crystalline Solids K14 of 19 Part A Classi.docxIntermolecular Interactions Crystalline Solids K14 of 19 Part A Classi.docx
Intermolecular Interactions Crystalline Solids K14 of 19 Part A Classi.docxdiegor62
 
Integrative Problems equire the integration of multiple concepts to fi.docx
Integrative Problems equire the integration of multiple concepts to fi.docxIntegrative Problems equire the integration of multiple concepts to fi.docx
Integrative Problems equire the integration of multiple concepts to fi.docxdiegor62
 
Insight Communications Promotes employees with good technical skills i.docx
Insight Communications Promotes employees with good technical skills i.docxInsight Communications Promotes employees with good technical skills i.docx
Insight Communications Promotes employees with good technical skills i.docxdiegor62
 
Infrared radiation is also called IR- Describe how it is different fro (1).docx
Infrared radiation is also called IR- Describe how it is different fro (1).docxInfrared radiation is also called IR- Describe how it is different fro (1).docx
Infrared radiation is also called IR- Describe how it is different fro (1).docxdiegor62
 
Infrared radiation is also called IR- Describe how it is different fro.docx
Infrared radiation is also called IR- Describe how it is different fro.docxInfrared radiation is also called IR- Describe how it is different fro.docx
Infrared radiation is also called IR- Describe how it is different fro.docxdiegor62
 
Initial Knowledge Check For each row in the table below- decide whethe.docx
Initial Knowledge Check For each row in the table below- decide whethe.docxInitial Knowledge Check For each row in the table below- decide whethe.docx
Initial Knowledge Check For each row in the table below- decide whethe.docxdiegor62
 
Is the ability of the human ear better or worse than the sonic capabil.docx
Is the ability of the human ear better or worse than the sonic capabil.docxIs the ability of the human ear better or worse than the sonic capabil.docx
Is the ability of the human ear better or worse than the sonic capabil.docxdiegor62
 
Is my half equation and ionic equation from the answer key correct- I.docx
Is my half equation and ionic equation from the answer key correct- I.docxIs my half equation and ionic equation from the answer key correct- I.docx
Is my half equation and ionic equation from the answer key correct- I.docxdiegor62
 
Inorganic Chemistry - Wurtzite vs- Rock-Salt Structures Beryllium oxid.docx
Inorganic Chemistry - Wurtzite vs- Rock-Salt Structures Beryllium oxid.docxInorganic Chemistry - Wurtzite vs- Rock-Salt Structures Beryllium oxid.docx
Inorganic Chemistry - Wurtzite vs- Rock-Salt Structures Beryllium oxid.docxdiegor62
 
Is it time for IPI to reconsider its salesforce organization by produc.docx
Is it time for IPI to reconsider its salesforce organization by produc.docxIs it time for IPI to reconsider its salesforce organization by produc.docx
Is it time for IPI to reconsider its salesforce organization by produc.docxdiegor62
 
INITIALS- 22- Which of the following represents a combustion reaction-.docx
INITIALS- 22- Which of the following represents a combustion reaction-.docxINITIALS- 22- Which of the following represents a combustion reaction-.docx
INITIALS- 22- Which of the following represents a combustion reaction-.docxdiegor62
 

Más de diegor62 (20)

Introductory Aocounting u 2014 1- Managerial information- accounting m.docx
Introductory Aocounting u 2014 1- Managerial information- accounting m.docxIntroductory Aocounting u 2014 1- Managerial information- accounting m.docx
Introductory Aocounting u 2014 1- Managerial information- accounting m.docx
 
Introduction to Java Programming 10th ed --25-4 (Implement preorder t.docx
Introduction to Java Programming 10th ed  --25-4 (Implement preorder t.docxIntroduction to Java Programming 10th ed  --25-4 (Implement preorder t.docx
Introduction to Java Programming 10th ed --25-4 (Implement preorder t.docx
 
Indicate the functions of the agent process in a network operating sys.docx
Indicate the functions of the agent process in a network operating sys.docxIndicate the functions of the agent process in a network operating sys.docx
Indicate the functions of the agent process in a network operating sys.docx
 
Interpretation 102-4 in the AICPA Code of Professional Conduct calls f.docx
Interpretation 102-4 in the AICPA Code of Professional Conduct calls f.docxInterpretation 102-4 in the AICPA Code of Professional Conduct calls f.docx
Interpretation 102-4 in the AICPA Code of Professional Conduct calls f.docx
 
internet domain names are linked to trademark issues- Technology makes.docx
internet domain names are linked to trademark issues- Technology makes.docxinternet domain names are linked to trademark issues- Technology makes.docx
internet domain names are linked to trademark issues- Technology makes.docx
 
Internet network management framework as consisting of three major par.docx
Internet network management framework as consisting of three major par.docxInternet network management framework as consisting of three major par.docx
Internet network management framework as consisting of three major par.docx
 
Internet Programming ORM This question uses the following two model cl.docx
Internet Programming ORM This question uses the following two model cl.docxInternet Programming ORM This question uses the following two model cl.docx
Internet Programming ORM This question uses the following two model cl.docx
 
international ECO 305 course- how does culture embrace globalization a.docx
international ECO 305 course- how does culture embrace globalization a.docxinternational ECO 305 course- how does culture embrace globalization a.docx
international ECO 305 course- how does culture embrace globalization a.docx
 
International business is conducted outside of the home country- Natio.docx
International business is conducted outside of the home country- Natio.docxInternational business is conducted outside of the home country- Natio.docx
International business is conducted outside of the home country- Natio.docx
 
Intermolecular Interactions Crystalline Solids K14 of 19 Part A Classi.docx
Intermolecular Interactions Crystalline Solids K14 of 19 Part A Classi.docxIntermolecular Interactions Crystalline Solids K14 of 19 Part A Classi.docx
Intermolecular Interactions Crystalline Solids K14 of 19 Part A Classi.docx
 
Integrative Problems equire the integration of multiple concepts to fi.docx
Integrative Problems equire the integration of multiple concepts to fi.docxIntegrative Problems equire the integration of multiple concepts to fi.docx
Integrative Problems equire the integration of multiple concepts to fi.docx
 
Insight Communications Promotes employees with good technical skills i.docx
Insight Communications Promotes employees with good technical skills i.docxInsight Communications Promotes employees with good technical skills i.docx
Insight Communications Promotes employees with good technical skills i.docx
 
Infrared radiation is also called IR- Describe how it is different fro (1).docx
Infrared radiation is also called IR- Describe how it is different fro (1).docxInfrared radiation is also called IR- Describe how it is different fro (1).docx
Infrared radiation is also called IR- Describe how it is different fro (1).docx
 
Infrared radiation is also called IR- Describe how it is different fro.docx
Infrared radiation is also called IR- Describe how it is different fro.docxInfrared radiation is also called IR- Describe how it is different fro.docx
Infrared radiation is also called IR- Describe how it is different fro.docx
 
Initial Knowledge Check For each row in the table below- decide whethe.docx
Initial Knowledge Check For each row in the table below- decide whethe.docxInitial Knowledge Check For each row in the table below- decide whethe.docx
Initial Knowledge Check For each row in the table below- decide whethe.docx
 
Is the ability of the human ear better or worse than the sonic capabil.docx
Is the ability of the human ear better or worse than the sonic capabil.docxIs the ability of the human ear better or worse than the sonic capabil.docx
Is the ability of the human ear better or worse than the sonic capabil.docx
 
Is my half equation and ionic equation from the answer key correct- I.docx
Is my half equation and ionic equation from the answer key correct- I.docxIs my half equation and ionic equation from the answer key correct- I.docx
Is my half equation and ionic equation from the answer key correct- I.docx
 
Inorganic Chemistry - Wurtzite vs- Rock-Salt Structures Beryllium oxid.docx
Inorganic Chemistry - Wurtzite vs- Rock-Salt Structures Beryllium oxid.docxInorganic Chemistry - Wurtzite vs- Rock-Salt Structures Beryllium oxid.docx
Inorganic Chemistry - Wurtzite vs- Rock-Salt Structures Beryllium oxid.docx
 
Is it time for IPI to reconsider its salesforce organization by produc.docx
Is it time for IPI to reconsider its salesforce organization by produc.docxIs it time for IPI to reconsider its salesforce organization by produc.docx
Is it time for IPI to reconsider its salesforce organization by produc.docx
 
INITIALS- 22- Which of the following represents a combustion reaction-.docx
INITIALS- 22- Which of the following represents a combustion reaction-.docxINITIALS- 22- Which of the following represents a combustion reaction-.docx
INITIALS- 22- Which of the following represents a combustion reaction-.docx
 

Último

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 

Último (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 

R- For some array of size- ROW by COLUMN- compute and display the aver.docx

  • 1. R. For some array of size, ROW by COLUMN, compute and display the average of the left-to- right diagonal in java Solution import java.util.Scanner; public class SumOfDiagonals { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int row,column; System.out.print("Enter row: "); row = getInt(sc, ""); System.out.print("Enter column: "); column = getInt(sc, ""); //Declare 2 Dimensional Arrays int[][] matrix = new int[row][column]; int sum = 0; // Input Matrix System.out.println("Enter matrix "); for (int i = 0; i < row; i++) { System.out.println("Enter elements of " + i + " row"); for (int j = 0; j < column; j++) { matrix[i][j] = getInt(sc, ""); } } // Compute Sum of main diagonal elements for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { if (i == j) { sum += matrix[i][j];
  • 2. } } } int n; if(row > column) n = column; else n = row; System.out.println("Sum of Diagonal Elements is " + sum); System.out.println("Average of Diagonal Elements is " + sum/n); } public static int getInt(Scanner sc, String prompt) { int integer = 0; boolean isValid = false; while (isValid == false) { System.out.print(prompt); if (sc.hasNextInt()) { integer = sc.nextInt(); isValid = true; } else { System.err.println("Error! Invalid number. Try again."); } sc.nextLine(); } return integer; } }