|
Daniel try my code below and then compare the two and see where you
might be having trouble at. import javax.swing.JOptionPane; public class SplitName { /** * @param args */ public static void main(String[] args) { // Step 1 String firstPerson; String secondPerson; // Step 2 firstPerson = JOptionPane.showInputDialog("Please enter your name"); secondPerson = JOptionPane.showInputDialog("Please enter your name"); // Step 3 // creating the two arrays String[] firstPersonName = new String[2]; String[] secondPersonName = new String[2]; // splitting the two names into the newly created array firstPersonName = firstPerson.split(" "); secondPersonName = secondPerson.split(" "); // Step 4 if (firstPersonName[0].length() > secondPersonName[0].length()) { System.out.println(firstPersonName[0] + " has longer first name than " + secondPersonName[0]); } else if (firstPersonName[0].length() == secondPersonName[0].length()) { System.out.println(secondPersonName[0] + "'s first name is the same length as " + firstPersonName[0] + "'s first name."); } else { System.out.println(secondPersonName[0] + " has longer first name than " + firstPersonName[0]); } } } Stephen Ruben wrote: the personNameInstance is for contain the name of the person and this variables is not initialized with the names of persons (you need load the names in the dialog box in this variables), and the nameArrayForPerson is for split the first and the second name in this array of string, look this code: |
- [java programming] need help with lab-1036 Daniel Mays
- Re: [java programming] need help with lab-1036 Retnuh
- [java programming] Re: need help with lab-1036 Ruben
- [java programming] Re: need help with lab-1036 Ruben
- Re: [java programming] Re: need help with lab-1036 Retnuh
