SlideShare a Scribd company logo
1 of 2
Download to read offline
Design and implement a Java program for programming exercise 8.27, page 315 (name it
Columnsorting) as described in the problem statement. Write method sortColumns() as specified
(you may change the element type to integer). Notice that this method returns a new array, the
original array remains unchanged. To test this method, the main method of your program
prompts the user to enter a two-dimensional array and displays the original array followed by the
column-sorted array as shown in the sample run. Design the main method of your program such
that it allows the user to re-run the program with different inputs (i.e., use a loop). Document
your code, and organize and space the outputs properly. Use escape characters and formatting
objects when applicable.
Solution
ColumnSorting.java
public class ColumnSorting {
public static void main(String[] args) {
java.util.Scanner in = new java.util.Scanner(System.in);
System.out.println("Enter a 3-by-3 matrix row by row: ");
String firstRow = in.nextLine();
String firstRowValues[] = firstRow.split("s+");
String secondRow = in.nextLine();
String secondRowValues[] = secondRow.split("s+");
String thirdRow = in.nextLine();
String thirdRowValues[] = thirdRow.split("s+");
double a[][] = new double[3][3];
for(int i=0; i m[j+1][i]){
temp = m[j][i];
m[j][i] = m[j+1][i];
m[j+1][i] = temp;
}
}
}
return m;
}
}
Output:
Enter a 3-by-3 matrix row by row:
0.15 0.875 0.375
0.55 0.005 0.225
0.30 0.12 0.4
The column-sorted array is
0.15 0.005 0.225
0.3 0.12 0.375
0.55 0.875 0.4

More Related Content

Similar to Java program to sort columns of a 2D array

Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxchetanpatilcp783
 
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfStep 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfaloeplusint
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hotSergii Maliarov
 
VB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.pptVB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.pptBhuvanaR13
 
Java Tutorial Lab 5
Java Tutorial Lab 5Java Tutorial Lab 5
Java Tutorial Lab 5Berk Soysal
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywordsmanish kumar
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyworldchannel
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsKuntal Bhowmick
 
CMSC 350 HOMEWORK 1
CMSC 350 HOMEWORK 1CMSC 350 HOMEWORK 1
CMSC 350 HOMEWORK 1HamesKellor
 

Similar to Java program to sort columns of a 2D array (18)

Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfStep 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
 
Java execise
Java execiseJava execise
Java execise
 
VB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.pptVB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.ppt
 
Java Tutorial Lab 5
Java Tutorial Lab 5Java Tutorial Lab 5
Java Tutorial Lab 5
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
CH1 ARRAY (1).pptx
CH1 ARRAY (1).pptxCH1 ARRAY (1).pptx
CH1 ARRAY (1).pptx
 
Arrays
ArraysArrays
Arrays
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
Arrays
ArraysArrays
Arrays
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
CMSC 350 HOMEWORK 1
CMSC 350 HOMEWORK 1CMSC 350 HOMEWORK 1
CMSC 350 HOMEWORK 1
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 

More from duttakajal70

Explain the relevance of the rules against hearsay to digital eviden.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdfExplain the relevance of the rules against hearsay to digital eviden.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdfduttakajal70
 
Electric and magnetic fields in an electromagnetic wave are alway.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdfElectric and magnetic fields in an electromagnetic wave are alway.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdfduttakajal70
 
C# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdfC# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdfduttakajal70
 
During our laboratory exercise on cellular the Krebs cycle in.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdfDuring our laboratory exercise on cellular the Krebs cycle in.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdfduttakajal70
 
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdfduttakajal70
 
Define filtration and active transport.SolutionFiltration is t.pdf
Define filtration and active transport.SolutionFiltration is t.pdfDefine filtration and active transport.SolutionFiltration is t.pdf
Define filtration and active transport.SolutionFiltration is t.pdfduttakajal70
 
Why wouldnt you want to post a payment against an invoice directly.pdf
Why wouldnt you want to post a payment against an invoice directly.pdfWhy wouldnt you want to post a payment against an invoice directly.pdf
Why wouldnt you want to post a payment against an invoice directly.pdfduttakajal70
 
Cisco routers and switches use two configuration files. Where is the.pdf
Cisco routers and switches use two configuration files. Where is the.pdfCisco routers and switches use two configuration files. Where is the.pdf
Cisco routers and switches use two configuration files. Where is the.pdfduttakajal70
 
Which of the following is a simple compressible system A mixtur.pdf
Which of the following is a simple compressible system  A mixtur.pdfWhich of the following is a simple compressible system  A mixtur.pdf
Which of the following is a simple compressible system A mixtur.pdfduttakajal70
 
Which of the following statements is (are) trueI Walls Street i.pdf
Which of the following statements is (are) trueI  Walls Street i.pdfWhich of the following statements is (are) trueI  Walls Street i.pdf
Which of the following statements is (are) trueI Walls Street i.pdfduttakajal70
 
What would be the most effective method of reducing the incidence of .pdf
What would be the most effective method of reducing the incidence of .pdfWhat would be the most effective method of reducing the incidence of .pdf
What would be the most effective method of reducing the incidence of .pdfduttakajal70
 
What is a micelle What is a vesicle How are these structures the s.pdf
What is a micelle What is a vesicle How are these structures the s.pdfWhat is a micelle What is a vesicle How are these structures the s.pdf
What is a micelle What is a vesicle How are these structures the s.pdfduttakajal70
 
To determine her breathing rate, Miranda divides up her day into thre.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdfTo determine her breathing rate, Miranda divides up her day into thre.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdfduttakajal70
 
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdfOn January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdfduttakajal70
 
Name and describe the six main types of lymphatic cells, discuss the.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdfName and describe the six main types of lymphatic cells, discuss the.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdfduttakajal70
 
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdfLet X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdfduttakajal70
 
Java Program using RecursionWrite a program that reads in a file .pdf
Java Program using RecursionWrite a program that reads in a file .pdfJava Program using RecursionWrite a program that reads in a file .pdf
Java Program using RecursionWrite a program that reads in a file .pdfduttakajal70
 
In major league baseball, there are 5 teams in the Eastern division .pdf
In major league baseball, there are 5 teams in the Eastern division .pdfIn major league baseball, there are 5 teams in the Eastern division .pdf
In major league baseball, there are 5 teams in the Eastern division .pdfduttakajal70
 
Im off by a minus sign, can you find my error In a previous probl.pdf
Im off by a minus sign, can you find my error In a previous probl.pdfIm off by a minus sign, can you find my error In a previous probl.pdf
Im off by a minus sign, can you find my error In a previous probl.pdfduttakajal70
 
If the characteristic followed in the pedigree is X-linked recessiv.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdfIf the characteristic followed in the pedigree is X-linked recessiv.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdfduttakajal70
 

More from duttakajal70 (20)

Explain the relevance of the rules against hearsay to digital eviden.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdfExplain the relevance of the rules against hearsay to digital eviden.pdf
Explain the relevance of the rules against hearsay to digital eviden.pdf
 
Electric and magnetic fields in an electromagnetic wave are alway.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdfElectric and magnetic fields in an electromagnetic wave are alway.pdf
Electric and magnetic fields in an electromagnetic wave are alway.pdf
 
C# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdfC# code pleaseWrite a program that creates a link list object of 1.pdf
C# code pleaseWrite a program that creates a link list object of 1.pdf
 
During our laboratory exercise on cellular the Krebs cycle in.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdfDuring our laboratory exercise on cellular the Krebs cycle in.pdf
During our laboratory exercise on cellular the Krebs cycle in.pdf
 
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
25. On January 3, Pippin Corporation purchased 1,900 shares of the c.pdf
 
Define filtration and active transport.SolutionFiltration is t.pdf
Define filtration and active transport.SolutionFiltration is t.pdfDefine filtration and active transport.SolutionFiltration is t.pdf
Define filtration and active transport.SolutionFiltration is t.pdf
 
Why wouldnt you want to post a payment against an invoice directly.pdf
Why wouldnt you want to post a payment against an invoice directly.pdfWhy wouldnt you want to post a payment against an invoice directly.pdf
Why wouldnt you want to post a payment against an invoice directly.pdf
 
Cisco routers and switches use two configuration files. Where is the.pdf
Cisco routers and switches use two configuration files. Where is the.pdfCisco routers and switches use two configuration files. Where is the.pdf
Cisco routers and switches use two configuration files. Where is the.pdf
 
Which of the following is a simple compressible system A mixtur.pdf
Which of the following is a simple compressible system  A mixtur.pdfWhich of the following is a simple compressible system  A mixtur.pdf
Which of the following is a simple compressible system A mixtur.pdf
 
Which of the following statements is (are) trueI Walls Street i.pdf
Which of the following statements is (are) trueI  Walls Street i.pdfWhich of the following statements is (are) trueI  Walls Street i.pdf
Which of the following statements is (are) trueI Walls Street i.pdf
 
What would be the most effective method of reducing the incidence of .pdf
What would be the most effective method of reducing the incidence of .pdfWhat would be the most effective method of reducing the incidence of .pdf
What would be the most effective method of reducing the incidence of .pdf
 
What is a micelle What is a vesicle How are these structures the s.pdf
What is a micelle What is a vesicle How are these structures the s.pdfWhat is a micelle What is a vesicle How are these structures the s.pdf
What is a micelle What is a vesicle How are these structures the s.pdf
 
To determine her breathing rate, Miranda divides up her day into thre.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdfTo determine her breathing rate, Miranda divides up her day into thre.pdf
To determine her breathing rate, Miranda divides up her day into thre.pdf
 
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdfOn January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
On January 29th, 2014, the Royal Caribbean cruise ship Explorer of.pdf
 
Name and describe the six main types of lymphatic cells, discuss the.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdfName and describe the six main types of lymphatic cells, discuss the.pdf
Name and describe the six main types of lymphatic cells, discuss the.pdf
 
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdfLet X1, X2, . . . , Xn be n independent continuous random variables,.pdf
Let X1, X2, . . . , Xn be n independent continuous random variables,.pdf
 
Java Program using RecursionWrite a program that reads in a file .pdf
Java Program using RecursionWrite a program that reads in a file .pdfJava Program using RecursionWrite a program that reads in a file .pdf
Java Program using RecursionWrite a program that reads in a file .pdf
 
In major league baseball, there are 5 teams in the Eastern division .pdf
In major league baseball, there are 5 teams in the Eastern division .pdfIn major league baseball, there are 5 teams in the Eastern division .pdf
In major league baseball, there are 5 teams in the Eastern division .pdf
 
Im off by a minus sign, can you find my error In a previous probl.pdf
Im off by a minus sign, can you find my error In a previous probl.pdfIm off by a minus sign, can you find my error In a previous probl.pdf
Im off by a minus sign, can you find my error In a previous probl.pdf
 
If the characteristic followed in the pedigree is X-linked recessiv.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdfIf the characteristic followed in the pedigree is X-linked recessiv.pdf
If the characteristic followed in the pedigree is X-linked recessiv.pdf
 

Recently uploaded

Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Java program to sort columns of a 2D array

  • 1. Design and implement a Java program for programming exercise 8.27, page 315 (name it Columnsorting) as described in the problem statement. Write method sortColumns() as specified (you may change the element type to integer). Notice that this method returns a new array, the original array remains unchanged. To test this method, the main method of your program prompts the user to enter a two-dimensional array and displays the original array followed by the column-sorted array as shown in the sample run. Design the main method of your program such that it allows the user to re-run the program with different inputs (i.e., use a loop). Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable. Solution ColumnSorting.java public class ColumnSorting { public static void main(String[] args) { java.util.Scanner in = new java.util.Scanner(System.in); System.out.println("Enter a 3-by-3 matrix row by row: "); String firstRow = in.nextLine(); String firstRowValues[] = firstRow.split("s+"); String secondRow = in.nextLine(); String secondRowValues[] = secondRow.split("s+"); String thirdRow = in.nextLine(); String thirdRowValues[] = thirdRow.split("s+"); double a[][] = new double[3][3]; for(int i=0; i m[j+1][i]){ temp = m[j][i]; m[j][i] = m[j+1][i]; m[j+1][i] = temp; } } } return m; } } Output:
  • 2. Enter a 3-by-3 matrix row by row: 0.15 0.875 0.375 0.55 0.005 0.225 0.30 0.12 0.4 The column-sorted array is 0.15 0.005 0.225 0.3 0.12 0.375 0.55 0.875 0.4