SlideShare una empresa de Scribd logo
1 de 2
Done in Java please. Create a program that prompts the user to enter two Strings. Then display
the Strings in alphabetical order. If the two Strings are equal, display a message that they are
equal rather than printing them in alphabetical order.
Solution
public class AlphabeticalOrder
{
public static void main(String[] args)
{
int n;
String temp;
java.util.Scanner scn= new java.util.Scanner(System.in); //creating object for number of strings
you want to store
System.out.print("Enter number of names you want to enter:");
n = scn.nextInt(); //assigning number to variable n
String names[] = new String[n];
java.util.Scanner s1 = new java.util.Scanner(System.in); //creating object for strings
System.out.println("Enter all the names:");
for(int i = 0; i < n; i++) //for loop for comparing strings
{
names[i] = s1.nextLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.print("Names in Sorted Order:"); // printing strings in sorted order
for (int i = 0; i < n - 1; i++)
{
System.out.print(names[i] + ",");
}
System.out.print(names[n - 1]);
}
}

Más contenido relacionado

Similar a Java program to order Strings alphabetically or check equality

Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptxKimVeeL
 
Write a program that creates a LinkedList object of 10 characters- the.docx
Write a program that creates a LinkedList object of 10 characters- the.docxWrite a program that creates a LinkedList object of 10 characters- the.docx
Write a program that creates a LinkedList object of 10 characters- the.docxlez31palka
 
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdfCountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdfaparnatiwari291
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)Tak Lee
 
Assume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdfAssume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdfezzi552
 

Similar a Java program to order Strings alphabetically or check equality (6)

Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Write a program that creates a LinkedList object of 10 characters- the.docx
Write a program that creates a LinkedList object of 10 characters- the.docxWrite a program that creates a LinkedList object of 10 characters- the.docx
Write a program that creates a LinkedList object of 10 characters- the.docx
 
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdfCountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
Assume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdfAssume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdf
 

Más de edwardk6

Identify which of the following is NOT a TCP-IP Attack- Question 5 opt.docx
Identify which of the following is NOT a TCP-IP Attack- Question 5 opt.docxIdentify which of the following is NOT a TCP-IP Attack- Question 5 opt.docx
Identify which of the following is NOT a TCP-IP Attack- Question 5 opt.docxedwardk6
 
Identifying Matter- Physical Properties (Section 1-4 15- The elements.docx
Identifying Matter- Physical Properties (Section 1-4 15- The elements.docxIdentifying Matter- Physical Properties (Section 1-4 15- The elements.docx
Identifying Matter- Physical Properties (Section 1-4 15- The elements.docxedwardk6
 
Identifying aclds and bases by their reaction with water Kri Some chem.docx
Identifying aclds and bases by their reaction with water Kri Some chem.docxIdentifying aclds and bases by their reaction with water Kri Some chem.docx
Identifying aclds and bases by their reaction with water Kri Some chem.docxedwardk6
 
Identify the two primary sources of stockholders equity- and which sou.docx
Identify the two primary sources of stockholders equity- and which sou.docxIdentify the two primary sources of stockholders equity- and which sou.docx
Identify the two primary sources of stockholders equity- and which sou.docxedwardk6
 
If you had a system- that had large amounts of daily data inflows- tha.docx
If you had a system- that had large amounts of daily data inflows- tha.docxIf you had a system- that had large amounts of daily data inflows- tha.docx
If you had a system- that had large amounts of daily data inflows- tha.docxedwardk6
 
If two points are in a common reference frame- then a They are not in.docx
If two points are in a common reference frame- then a They are not in.docxIf two points are in a common reference frame- then a They are not in.docx
If two points are in a common reference frame- then a They are not in.docxedwardk6
 
Identify at least two types of system architectures that work well in.docx
Identify at least two types of system architectures that work well in.docxIdentify at least two types of system architectures that work well in.docx
Identify at least two types of system architectures that work well in.docxedwardk6
 
Identify and prioritize information assets- Identify and prioritize th.docx
Identify and prioritize information assets- Identify and prioritize th.docxIdentify and prioritize information assets- Identify and prioritize th.docx
Identify and prioritize information assets- Identify and prioritize th.docxedwardk6
 
If the Android platform you are developing for does not support fragme.docx
If the Android platform you are developing for does not support fragme.docxIf the Android platform you are developing for does not support fragme.docx
If the Android platform you are developing for does not support fragme.docxedwardk6
 
E13-7 On January 1- 2010- the stockholders-' equity section of Nunez C.docx
E13-7 On January 1- 2010- the stockholders-' equity section of Nunez C.docxE13-7 On January 1- 2010- the stockholders-' equity section of Nunez C.docx
E13-7 On January 1- 2010- the stockholders-' equity section of Nunez C.docxedwardk6
 
E 4- Elijah Samuels and Tony Winslow agreed to form a partnership- Sam.docx
E 4- Elijah Samuels and Tony Winslow agreed to form a partnership- Sam.docxE 4- Elijah Samuels and Tony Winslow agreed to form a partnership- Sam.docx
E 4- Elijah Samuels and Tony Winslow agreed to form a partnership- Sam.docxedwardk6
 
During October- Wichita Light Company experiences the following transa.docx
During October- Wichita Light Company experiences the following transa.docxDuring October- Wichita Light Company experiences the following transa.docx
During October- Wichita Light Company experiences the following transa.docxedwardk6
 
During a total lunar eclipse- in which the moon passes entirely into t.docx
During a total lunar eclipse- in which the moon passes entirely into t.docxDuring a total lunar eclipse- in which the moon passes entirely into t.docx
During a total lunar eclipse- in which the moon passes entirely into t.docxedwardk6
 
During 2011- Arthur Corportation reported a net income of $3-059-000-.docx
During 2011- Arthur Corportation reported a net income of $3-059-000-.docxDuring 2011- Arthur Corportation reported a net income of $3-059-000-.docx
During 2011- Arthur Corportation reported a net income of $3-059-000-.docxedwardk6
 
Driving School has 4 learning centres- The network of each learning ce.docx
Driving School has 4 learning centres- The network of each learning ce.docxDriving School has 4 learning centres- The network of each learning ce.docx
Driving School has 4 learning centres- The network of each learning ce.docxedwardk6
 
Donnie Hilfiger has two classes of stock authorized- S1 par preferred.docx
Donnie Hilfiger has two classes of stock authorized- S1 par preferred.docxDonnie Hilfiger has two classes of stock authorized- S1 par preferred.docx
Donnie Hilfiger has two classes of stock authorized- S1 par preferred.docxedwardk6
 
Doris Washington recently assumed her new position as HR Director at t.docx
Doris Washington recently assumed her new position as HR Director at t.docxDoris Washington recently assumed her new position as HR Director at t.docx
Doris Washington recently assumed her new position as HR Director at t.docxedwardk6
 
Doppler Effect- True or False John is listening to a horn- He knows th.docx
Doppler Effect- True or False John is listening to a horn- He knows th.docxDoppler Effect- True or False John is listening to a horn- He knows th.docx
Doppler Effect- True or False John is listening to a horn- He knows th.docxedwardk6
 
DQ #4 Explain the US Government Thrift Savings Plans-SolutionThe US Go.docx
DQ #4 Explain the US Government Thrift Savings Plans-SolutionThe US Go.docxDQ #4 Explain the US Government Thrift Savings Plans-SolutionThe US Go.docx
DQ #4 Explain the US Government Thrift Savings Plans-SolutionThe US Go.docxedwardk6
 

Más de edwardk6 (19)

Identify which of the following is NOT a TCP-IP Attack- Question 5 opt.docx
Identify which of the following is NOT a TCP-IP Attack- Question 5 opt.docxIdentify which of the following is NOT a TCP-IP Attack- Question 5 opt.docx
Identify which of the following is NOT a TCP-IP Attack- Question 5 opt.docx
 
Identifying Matter- Physical Properties (Section 1-4 15- The elements.docx
Identifying Matter- Physical Properties (Section 1-4 15- The elements.docxIdentifying Matter- Physical Properties (Section 1-4 15- The elements.docx
Identifying Matter- Physical Properties (Section 1-4 15- The elements.docx
 
Identifying aclds and bases by their reaction with water Kri Some chem.docx
Identifying aclds and bases by their reaction with water Kri Some chem.docxIdentifying aclds and bases by their reaction with water Kri Some chem.docx
Identifying aclds and bases by their reaction with water Kri Some chem.docx
 
Identify the two primary sources of stockholders equity- and which sou.docx
Identify the two primary sources of stockholders equity- and which sou.docxIdentify the two primary sources of stockholders equity- and which sou.docx
Identify the two primary sources of stockholders equity- and which sou.docx
 
If you had a system- that had large amounts of daily data inflows- tha.docx
If you had a system- that had large amounts of daily data inflows- tha.docxIf you had a system- that had large amounts of daily data inflows- tha.docx
If you had a system- that had large amounts of daily data inflows- tha.docx
 
If two points are in a common reference frame- then a They are not in.docx
If two points are in a common reference frame- then a They are not in.docxIf two points are in a common reference frame- then a They are not in.docx
If two points are in a common reference frame- then a They are not in.docx
 
Identify at least two types of system architectures that work well in.docx
Identify at least two types of system architectures that work well in.docxIdentify at least two types of system architectures that work well in.docx
Identify at least two types of system architectures that work well in.docx
 
Identify and prioritize information assets- Identify and prioritize th.docx
Identify and prioritize information assets- Identify and prioritize th.docxIdentify and prioritize information assets- Identify and prioritize th.docx
Identify and prioritize information assets- Identify and prioritize th.docx
 
If the Android platform you are developing for does not support fragme.docx
If the Android platform you are developing for does not support fragme.docxIf the Android platform you are developing for does not support fragme.docx
If the Android platform you are developing for does not support fragme.docx
 
E13-7 On January 1- 2010- the stockholders-' equity section of Nunez C.docx
E13-7 On January 1- 2010- the stockholders-' equity section of Nunez C.docxE13-7 On January 1- 2010- the stockholders-' equity section of Nunez C.docx
E13-7 On January 1- 2010- the stockholders-' equity section of Nunez C.docx
 
E 4- Elijah Samuels and Tony Winslow agreed to form a partnership- Sam.docx
E 4- Elijah Samuels and Tony Winslow agreed to form a partnership- Sam.docxE 4- Elijah Samuels and Tony Winslow agreed to form a partnership- Sam.docx
E 4- Elijah Samuels and Tony Winslow agreed to form a partnership- Sam.docx
 
During October- Wichita Light Company experiences the following transa.docx
During October- Wichita Light Company experiences the following transa.docxDuring October- Wichita Light Company experiences the following transa.docx
During October- Wichita Light Company experiences the following transa.docx
 
During a total lunar eclipse- in which the moon passes entirely into t.docx
During a total lunar eclipse- in which the moon passes entirely into t.docxDuring a total lunar eclipse- in which the moon passes entirely into t.docx
During a total lunar eclipse- in which the moon passes entirely into t.docx
 
During 2011- Arthur Corportation reported a net income of $3-059-000-.docx
During 2011- Arthur Corportation reported a net income of $3-059-000-.docxDuring 2011- Arthur Corportation reported a net income of $3-059-000-.docx
During 2011- Arthur Corportation reported a net income of $3-059-000-.docx
 
Driving School has 4 learning centres- The network of each learning ce.docx
Driving School has 4 learning centres- The network of each learning ce.docxDriving School has 4 learning centres- The network of each learning ce.docx
Driving School has 4 learning centres- The network of each learning ce.docx
 
Donnie Hilfiger has two classes of stock authorized- S1 par preferred.docx
Donnie Hilfiger has two classes of stock authorized- S1 par preferred.docxDonnie Hilfiger has two classes of stock authorized- S1 par preferred.docx
Donnie Hilfiger has two classes of stock authorized- S1 par preferred.docx
 
Doris Washington recently assumed her new position as HR Director at t.docx
Doris Washington recently assumed her new position as HR Director at t.docxDoris Washington recently assumed her new position as HR Director at t.docx
Doris Washington recently assumed her new position as HR Director at t.docx
 
Doppler Effect- True or False John is listening to a horn- He knows th.docx
Doppler Effect- True or False John is listening to a horn- He knows th.docxDoppler Effect- True or False John is listening to a horn- He knows th.docx
Doppler Effect- True or False John is listening to a horn- He knows th.docx
 
DQ #4 Explain the US Government Thrift Savings Plans-SolutionThe US Go.docx
DQ #4 Explain the US Government Thrift Savings Plans-SolutionThe US Go.docxDQ #4 Explain the US Government Thrift Savings Plans-SolutionThe US Go.docx
DQ #4 Explain the US Government Thrift Savings Plans-SolutionThe US Go.docx
 

Último

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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 ...EduSkills OECD
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Último (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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 ...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
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
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Java program to order Strings alphabetically or check equality

  • 1. Done in Java please. Create a program that prompts the user to enter two Strings. Then display the Strings in alphabetical order. If the two Strings are equal, display a message that they are equal rather than printing them in alphabetical order. Solution public class AlphabeticalOrder { public static void main(String[] args) { int n; String temp; java.util.Scanner scn= new java.util.Scanner(System.in); //creating object for number of strings you want to store System.out.print("Enter number of names you want to enter:"); n = scn.nextInt(); //assigning number to variable n String names[] = new String[n]; java.util.Scanner s1 = new java.util.Scanner(System.in); //creating object for strings System.out.println("Enter all the names:"); for(int i = 0; i < n; i++) //for loop for comparing strings { names[i] = s1.nextLine(); } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (names[i].compareTo(names[j])>0) { temp = names[i]; names[i] = names[j]; names[j] = temp; } } }
  • 2. System.out.print("Names in Sorted Order:"); // printing strings in sorted order for (int i = 0; i < n - 1; i++) { System.out.print(names[i] + ","); } System.out.print(names[n - 1]); } }