Argument Help!

Programming
Tutor: None Selected Time limit: 3 Hours

How can I make the mail from line come before the recpt to line in the output...

public class ArgsExample {<br>&nbsp; &nbsp;public static void main(String[] args) {<br>&nbsp; &nbsp; &nbsp;String from = "";<br>&nbsp; &nbsp; &nbsp;String to = "";<br>&nbsp; &nbsp; &nbsp;String subject = "";<br>&nbsp; &nbsp; &nbsp;String emailText = "";<br>&nbsp; &nbsp; &nbsp;System.out.println("number of args " + args.length);<br>&nbsp; &nbsp; &nbsp;for (int i = 0; i < args.length; i++) <br>&nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;if (args[i].startsWith("From:")) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from = args[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println("MAIL " + from);<br>&nbsp; &nbsp; &nbsp; &nbsp;} else if (args[i].startsWith("To:")) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;to = args[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println("RCPT " + to);<br>&nbsp; &nbsp; &nbsp; &nbsp;} else if (args[i].startsWith("Subject:")) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;subject = args[i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(subject);<br>&nbsp; &nbsp; &nbsp; &nbsp;} else { // The rest<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;emailText += args[i]+" ";<br>&nbsp; &nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp; &nbsp;}// for<br>&nbsp; &nbsp; &nbsp;System.out.println(emailText);<br>&nbsp; &nbsp;}// main<br>}<br><br

The argument line is:

java ArgsExample To:peter999@gmail From:1234567@yahoo.com Subject:Meeting Body:See you at 1pm


The output is: 

number of args ###
MAIL FROM: 1234567@yahoo.com
RCPT TO: peter999@gmail
Subject: Meeting
Body: See you at 1pm


Oct 5th, 2013

This will work, it all depends on the order of results you are displaying. Don't print the results right after you read em, just store them in variables and then print it in the order you desire ! Below is the modified code and the output.

Let me know if you need anything else, cheers!

public class ArgsExample {
   public static void main(String[] args) {
     String from = "";
     String to = "";
     String subject = "";
     String emailText = "";
     System.out.println("number of args " + args.length);
     for (int i = 0; i < args.length; i++) 
     {
       if (args[i].startsWith("From:")) {
         from = args[i];
       } else if (args[i].startsWith("To:")) {
         to = args[i];
       } else if (args[i].startsWith("Subject:")) {
         subject = args[i];
       } else { // The rest
           emailText += args[i]+" ";
       }
     }// for
     
        System.out.println("MAIL " + from);
        System.out.println("RCPT " + to);
        System.out.println(subject);
System.out.println(emailText);
   }// main
}
OUTPUT
number of args 7
MAIL From:1234567@yahoo.com
RCPT To:peter999@gmail
Subject:Meeting
Body:See you at 1pm 

Oct 5th, 2013

Hi, did you check my answer? Please make the payment if you are satisfied with the answer.

Thanks!

Oct 5th, 2013

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Oct 5th, 2013
...
Oct 5th, 2013
Dec 11th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer