SlideShare ist ein Scribd-Unternehmen logo
1 von 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]);
}
}

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
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
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
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
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 

Kürzlich hochgeladen (20)

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
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
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
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
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 

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]); } }