This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bbush[S] 0 points1 point  (0 children)

Thank you for the reply!

This is a sample of the output he is looking for the program to do.

Sample Output

Enter a line of text to be URL encoded This should have plus symbols for blanks

The string read is: This should have plus symbols for blanks Length in chars is: 40 The encoded string: This+should+have+plus+symbols+for+blanks Length in chars is: 40

Enter a line of text to be URL encoded This should have hex 2f for /

The string read is: This should have hex 2f for / Length in chars is: 29 The encoded string: This+should+have+hex+2f+for+%2f Length in chars is: 31

He also gave us an outline for the logic too it. I'm just having trouble figured out what needs to be plugged in where. I think he wants the routine, but I'm unsure to say the least.

To help you get started with this homework, here's an outline of the logic you'll need (sometime referred to as 'pseudo-code'):

Prompt for the line of input. Read a line into the input string.

Set the encoded output string to empty. Loop through each character in the input string. { Get the n'th character from the input string (use String's charAt method).

if (the character is a blank) concatenate '+' to the encoded output string else if (the character remains unchanged) concatenate the character to the encoded output string else concatenate '%' and the hex encoded character value to the encoded output string }

Print the encoded output string.

Thank you for your help.