SlideShare a Scribd company logo
1 of 4
Please help in Java
1. Declare and initialize the 2 dimensional array a b c d e f g h i Next print one diagonal of this
"determinant" on one line , and then the other diagonal, separated by a line from the first
diagonal you printed. 2. Generate the two-dimensional string array: Roses are red Violets are
blue I've never found someone as patient As you Substitute "but I have commitment issues" for
the last line in the above poem and print the whole poem.
Solution
/*Java program to print diagonals of character array and print lines of poem..*/
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class diagArr
{
public static void main (String[] args) throws java.lang.Exception
{
// initializing two dimensional array
char[][] arr1 = { {'a', 'b','c'}, {'d', 'e','f'}, {'g', 'h','i'} };
System.out.println("Printing diagonals...");
System.out.println(arr1[0][0]+" t"+arr1[1][1]+"t"+arr1[2][2]);
System.out.println(" ");
System.out.println(arr1[0][2]+"t"+arr1[1][1]+"t"+arr1[2][0]);
System.out.println(" ");
// initializing second two dimensional array
//String[][] arr2 = { {"Roses", "are","Red"}, {"Violets", "are","Blue"}, {" Ive",
"never","found"},{"someone", "as", "patient"},{"As","you","" }};
// initializing second two dimensional array
String[][] arr2 = new String[6][3];
arr2[0][0] = "Roses";
arr2[0][1] = "are";
arr2[0][2] = "Red";
arr2[1][0] = "Violets";
arr2[1][1] = "are";
arr2[1][2] = "Blue";
arr2[2][0] = "Ive";
arr2[2][1] = "never";
arr2[2][2] = "found";
arr2[3][0] = "someone";
arr2[3][1] = "as";
arr2[3][2] = "patient";
arr2[4][0] = "as";
arr2[4][1] = "you";
System.out.println("Printing poem...");
arr2[4][0]="but";
arr2[4][1]="I";
arr2[4][2]="have";
arr2[5][0]="commitment";
arr2[5][1]="issues";
arr2[5][2]=" ";
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 3; j++) {
System.out.println(arr2[i][j]+"t");
}
System.out.println(" ");
}//second for loop ends
}//main ends
}//class ends
Output:
Printing diagonals...
a   e  i
c  e  g
Printing poem...
Roses
are
Red
Violets
are
Blue
Ive
never
found
someone
as
patient
but
I
have
commitment
issues
Please help in Java 1- Declare and initialize the 2 dimensional array.docx

More Related Content

More from rtodd19

Please answer part c of the question- Thank you- The International Ato.docx
Please answer part c of the question- Thank you- The International Ato.docxPlease answer part c of the question- Thank you- The International Ato.docx
Please answer part c of the question- Thank you- The International Ato.docx
rtodd19
 
Pictorialize a human being as a computer system-SolutionThe human nerv.docx
Pictorialize a human being as a computer system-SolutionThe human nerv.docxPictorialize a human being as a computer system-SolutionThe human nerv.docx
Pictorialize a human being as a computer system-SolutionThe human nerv.docx
rtodd19
 
Personal Trainer- Inc- owns and operates fitness centers in a dozen Mi.docx
Personal Trainer- Inc- owns and operates fitness centers in a dozen Mi.docxPersonal Trainer- Inc- owns and operates fitness centers in a dozen Mi.docx
Personal Trainer- Inc- owns and operates fitness centers in a dozen Mi.docx
rtodd19
 
Peruse the readings by Bennis and Nanus- Schein- and Ulrich and Lake-.docx
Peruse the readings by Bennis and Nanus- Schein- and Ulrich and Lake-.docxPeruse the readings by Bennis and Nanus- Schein- and Ulrich and Lake-.docx
Peruse the readings by Bennis and Nanus- Schein- and Ulrich and Lake-.docx
rtodd19
 
Why do some converging technologies raise special ethical and social i.docx
Why do some converging technologies raise special ethical and social i.docxWhy do some converging technologies raise special ethical and social i.docx
Why do some converging technologies raise special ethical and social i.docx
rtodd19
 
Why are concentrated interests and diffuse costs important in predicti.docx
Why are concentrated interests and diffuse costs important in predicti.docxWhy are concentrated interests and diffuse costs important in predicti.docx
Why are concentrated interests and diffuse costs important in predicti.docx
rtodd19
 
which sectors might constitute the critical infrastructures of turkey.docx
which sectors might constitute the critical infrastructures of turkey.docxwhich sectors might constitute the critical infrastructures of turkey.docx
which sectors might constitute the critical infrastructures of turkey.docx
rtodd19
 
Which of the responses includes all of the following that can form hyd.docx
Which of the responses includes all of the following that can form hyd.docxWhich of the responses includes all of the following that can form hyd.docx
Which of the responses includes all of the following that can form hyd.docx
rtodd19
 

More from rtodd19 (20)

Please answer part c of the question- Thank you- The International Ato.docx
Please answer part c of the question- Thank you- The International Ato.docxPlease answer part c of the question- Thank you- The International Ato.docx
Please answer part c of the question- Thank you- The International Ato.docx
 
Pictorialize a human being as a computer system-SolutionThe human nerv.docx
Pictorialize a human being as a computer system-SolutionThe human nerv.docxPictorialize a human being as a computer system-SolutionThe human nerv.docx
Pictorialize a human being as a computer system-SolutionThe human nerv.docx
 
Personal Trainer- Inc- owns and operates fitness centers in a dozen Mi.docx
Personal Trainer- Inc- owns and operates fitness centers in a dozen Mi.docxPersonal Trainer- Inc- owns and operates fitness centers in a dozen Mi.docx
Personal Trainer- Inc- owns and operates fitness centers in a dozen Mi.docx
 
Peruse the readings by Bennis and Nanus- Schein- and Ulrich and Lake-.docx
Peruse the readings by Bennis and Nanus- Schein- and Ulrich and Lake-.docxPeruse the readings by Bennis and Nanus- Schein- and Ulrich and Lake-.docx
Peruse the readings by Bennis and Nanus- Schein- and Ulrich and Lake-.docx
 
Why do some authors view investment cash flow sensitivity as a symptom.docx
Why do some authors view investment cash flow sensitivity as a symptom.docxWhy do some authors view investment cash flow sensitivity as a symptom.docx
Why do some authors view investment cash flow sensitivity as a symptom.docx
 
Why do some converging technologies raise special ethical and social i.docx
Why do some converging technologies raise special ethical and social i.docxWhy do some converging technologies raise special ethical and social i.docx
Why do some converging technologies raise special ethical and social i.docx
 
Why do the outer stars in our galaxy not slow down- as Keplers laws of.docx
Why do the outer stars in our galaxy not slow down- as Keplers laws of.docxWhy do the outer stars in our galaxy not slow down- as Keplers laws of.docx
Why do the outer stars in our galaxy not slow down- as Keplers laws of.docx
 
Why are concentrated interests and diffuse costs important in predicti.docx
Why are concentrated interests and diffuse costs important in predicti.docxWhy are concentrated interests and diffuse costs important in predicti.docx
Why are concentrated interests and diffuse costs important in predicti.docx
 
Who are organizational stakeholders and what types of responsibilities.docx
Who are organizational stakeholders and what types of responsibilities.docxWho are organizational stakeholders and what types of responsibilities.docx
Who are organizational stakeholders and what types of responsibilities.docx
 
Who are the principle stake holders of the company- Did Dole treat the.docx
Who are the principle stake holders of the company- Did Dole treat the.docxWho are the principle stake holders of the company- Did Dole treat the.docx
Who are the principle stake holders of the company- Did Dole treat the.docx
 
Which type of network covers a contiguous geographic area- such as an.docx
Which type of network covers a contiguous geographic area- such as an.docxWhich type of network covers a contiguous geographic area- such as an.docx
Which type of network covers a contiguous geographic area- such as an.docx
 
Which space is the most abundant in 1-0 M of wak acid HCN solution- As.docx
Which space is the most abundant in 1-0 M of wak acid HCN solution- As.docxWhich space is the most abundant in 1-0 M of wak acid HCN solution- As.docx
Which space is the most abundant in 1-0 M of wak acid HCN solution- As.docx
 
which sectors might constitute the critical infrastructures of turkey.docx
which sectors might constitute the critical infrastructures of turkey.docxwhich sectors might constitute the critical infrastructures of turkey.docx
which sectors might constitute the critical infrastructures of turkey.docx
 
Which one of the following statements is true- Only one is true- Expla.docx
Which one of the following statements is true- Only one is true- Expla.docxWhich one of the following statements is true- Only one is true- Expla.docx
Which one of the following statements is true- Only one is true- Expla.docx
 
Which one of the following below would not be classified as an operati.docx
Which one of the following below would not be classified as an operati.docxWhich one of the following below would not be classified as an operati.docx
Which one of the following below would not be classified as an operati.docx
 
Which of the two main types of reactor design are the following- What.docx
Which of the two main types of reactor design are the following- What.docxWhich of the two main types of reactor design are the following- What.docx
Which of the two main types of reactor design are the following- What.docx
 
Which of the responses includes all of the following that can form hyd.docx
Which of the responses includes all of the following that can form hyd.docxWhich of the responses includes all of the following that can form hyd.docx
Which of the responses includes all of the following that can form hyd.docx
 
Which of the four operations on functions do you think is the easiest.docx
Which of the four operations on functions do you think is the easiest.docxWhich of the four operations on functions do you think is the easiest.docx
Which of the four operations on functions do you think is the easiest.docx
 
Which of the following would not appear in an IT acceptable use policy.docx
Which of the following would not appear in an IT acceptable use policy.docxWhich of the following would not appear in an IT acceptable use policy.docx
Which of the following would not appear in an IT acceptable use policy.docx
 
Which of the following would be soluable in water- Benzene C6H6 Diethy.docx
Which of the following would be soluable in water- Benzene C6H6 Diethy.docxWhich of the following would be soluable in water- Benzene C6H6 Diethy.docx
Which of the following would be soluable in water- Benzene C6H6 Diethy.docx
 

Recently uploaded

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
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
 
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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Please help in Java 1- Declare and initialize the 2 dimensional array.docx

  • 1. Please help in Java 1. Declare and initialize the 2 dimensional array a b c d e f g h i Next print one diagonal of this "determinant" on one line , and then the other diagonal, separated by a line from the first diagonal you printed. 2. Generate the two-dimensional string array: Roses are red Violets are blue I've never found someone as patient As you Substitute "but I have commitment issues" for the last line in the above poem and print the whole poem. Solution /*Java program to print diagonals of character array and print lines of poem..*/ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class diagArr { public static void main (String[] args) throws java.lang.Exception { // initializing two dimensional array char[][] arr1 = { {'a', 'b','c'}, {'d', 'e','f'}, {'g', 'h','i'} }; System.out.println("Printing diagonals..."); System.out.println(arr1[0][0]+" t"+arr1[1][1]+"t"+arr1[2][2]); System.out.println(" "); System.out.println(arr1[0][2]+"t"+arr1[1][1]+"t"+arr1[2][0]); System.out.println(" ");
  • 2. // initializing second two dimensional array //String[][] arr2 = { {"Roses", "are","Red"}, {"Violets", "are","Blue"}, {" Ive", "never","found"},{"someone", "as", "patient"},{"As","you","" }}; // initializing second two dimensional array String[][] arr2 = new String[6][3]; arr2[0][0] = "Roses"; arr2[0][1] = "are"; arr2[0][2] = "Red"; arr2[1][0] = "Violets"; arr2[1][1] = "are"; arr2[1][2] = "Blue"; arr2[2][0] = "Ive"; arr2[2][1] = "never"; arr2[2][2] = "found"; arr2[3][0] = "someone"; arr2[3][1] = "as"; arr2[3][2] = "patient"; arr2[4][0] = "as"; arr2[4][1] = "you"; System.out.println("Printing poem..."); arr2[4][0]="but"; arr2[4][1]="I"; arr2[4][2]="have"; arr2[5][0]="commitment"; arr2[5][1]="issues"; arr2[5][2]=" "; for (int i = 0; i < 6; i++) { for (int j = 0; j < 3; j++) { System.out.println(arr2[i][j]+"t"); } System.out.println(" "); }//second for loop ends }//main ends }//class ends Output:
  • 3. Printing diagonals... a   e  i c  e  g Printing poem... Roses are Red Violets are Blue Ive never found someone as patient but I have commitment issues