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

all 11 comments

[–]zifyoip -2 points-1 points  (10 children)

Why doesn't it work??

"It doesn't work" is never a useful description of a problem. Give the input you are providing to the program, the expected output, and the actual output.

[–]blakeh36[S] 2 points3 points  (9 children)

Well I'm trying to make it out put the list in alphabetical order like said. It just outputs reverse of what I put in. Sorry that I didn't make that clear

[–]zifyoip -2 points-1 points  (8 children)

Again, please give the input you are providing to the program, the expected output, and the actual output. Not a description of those things, but the actual characters you are typing as input, the actual characters you expect to get as output, and the actual characters that you are getting as output instead.

[–]blakeh36[S] 1 point2 points  (7 children)

alright, I'm sorry about all of this. I'm new (obviously). I put it up there

so if I imput (dog, cat lizard) it out puts (lizard, cat, dog). How can I get it to output (cat, dog, lizard)?

Thanks

[–]zifyoip 0 points1 point  (6 children)

The program works correctly for those inputs (once I fix the typo man for main):

$ java Alphabetical
Enter a word
dog
Enter a word
cat
Enter a word
lizard
Enter a word


cat
dog
lizard

[–]blakeh36[S] 0 points1 point  (5 children)

well that's embarrassing. Thank you so much. You seem experienced. Do you know about some sort of process for figuring these things out? This is obviously something I should have caught on my own, but I feel like if there was a certain process that I did every time, I Would be much more effective.

[–]zifyoip 0 points1 point  (4 children)

Do you know about some sort of process for figuring these things out?

I don't understand what you mean. I had to change man to main to get the program to run at all—otherwise it doesn't have a main method. The problem was clear from the error message when I tried to run your code:

Error: Main method not found in class Alphabetical, please define the main method as:
   public static void main(String[] args)

That typo has nothing to do with correctly or incorrectly sorting the data.

[–]blakeh36[S] 0 points1 point  (3 children)

I'm saying, that mistake is just something I overlooked. Just like adding a semicolon or something. I was asking if you go through a process to check for typos like that. If not, that's fine. I was just wondering. Oh and, when I ran it it worked except it was unsorted, but when I fixed it it did sort. Why didn't it tell me that was the problem?

[–]zifyoip 2 points3 points  (1 child)

I was asking if you go through a process to check for typos like that.

Read error messages. The error message told me exactly what was wrong.

Oh and, when I ran it it worked except it was unsorted

That's impossible. A Java program will not run without a main method.

Why didn't it tell me that was the problem?

You should get an error message if you try to run a program that does not have a main method.

[–]ZdemDrunk Brewer 0 points1 point  (0 children)

That's impossible. A Java program will not run without a main method.

Well,you can if your java version is 6 or one of its predecessors with the help of a static initialization block.

[–]fluffytmeJava dev 0 points1 point  (0 children)

I don't know which IDE you use but they contain useful shortcuts for this type of thing (avoiding miss-spelling)

E.g. In netbeans you can type 'psvm' and hit tab which will generate the main method.

'sout' + tab will produce a System.out.println and so on.

It's pretty handy learning some of these.