SortedNames.java - import [email protected] Lemuel M [email protected] Book Title From Control Structures through Objects by Tony Gaddis Page 189

SortedNames.java - import [email protected]

This preview shows page 1 out of 1 page.

import javax.swing.JOptionPane; /** * @author Lemuel M. Uhuru * @Date June 10, 2013 * Book Title: From Control Structures through Objects by Tony Gaddis * Page: 189 Problem 7: Sorted Names * @Description Write a program that asks the user to enter three names, * and then displays the names sorted in ascending order. */ public class SortedNames { public static void main(String[] args) { // Declare 3 string variables to hold three names String name1, name2, name3; // Prompt user for 3 names name1 = JOptionPane.showInputDialog("Enter the first name"); name2 = JOptionPane.showInputDialog("Enter the second name"); name3 = JOptionPane.showInputDialog("Enter the third name"); // Design decision structure to sort and display // the set of names in ascending order. if (name1.compareTo(name2) < 0 & name1.compareTo(name3) < 0)
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

Unformatted text preview: if (name2.compareTo(name3) < 0) JOptionPane.showMessageDialog(null, name1 + ", " + name2 + ", " + name3); else JOptionPane.showMessageDialog(null, name1 + ", " + name3 + ", " + name2); else if (name2.compareTo(name1) < 0 & name2.compareTo(name3) < 0) if (name1.compareTo(name3) < 0) JOptionPane.showMessageDialog(null, name2 + ", " + name1 + ", " + name3); else JOptionPane.showMessageDialog(null, name2 + ", " + name3 + ", " + name1); else if (name3.compareTo(name2) < 0 & name3.compareTo(name1) < 0) if (name2.compareTo(name1) < 0) JOptionPane.showMessageDialog(null, name3 + ", " + name2 + ", " + name1); else JOptionPane.showMessageDialog(null, name3 + ", " + name1 + ", " + name2); } }...
View Full Document

  • Spring '08
  • Garcia,D
  • Java Programming, Sort, Java Code, @author, Middle name, @date, @description, Lemuel M. Uhuru

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors