Hello guy
guys i am working in aprogram and still i didn't did it right?
the Qs. is to write a program that reads in 3 words from the user and then prints out the words in alphabetic order and.
this is my codes:
Please GUYS HELP ME!
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello guy
guys i am working in aprogram and still i didn't did it right?
the Qs. is to write a program that reads in 3 words from the user and then prints out the words in alphabetic order and.
this is my codes:
Please GUYS HELP ME!
Last edited by WantHelp; July 4th, 2011 at 01:51 PM.
Can you show what your program prints out?
Please wrap your code in code tags to preserve formatting. See: BB Code List - Java Forums
if you don't know what the compareToIgnoreCase method is returning, use printlns to show you.
For example:
System.out.println("third.compareToIgnoreCase(firs t)=" + third.compareToIgnoreCase(first) +
" third=" + third + ", first=" + first);
What programming techniques do you know how to use now? Do you know about arrays?
For this problem you would normally use arrays.
Otherwise if you are supposed to use if() then
can you describe the logic you are using to find the first, and then second and third?
I cant use array because i'm a beginner
and when it print i don't get the in order
for example if i wrote : cat cloud catch
i get cat catch catch
and i'm using eclipse program
and the the anwser should be by if statement and compareToIgnoreCase method
Before you write any code, you need to design the logic for what the code is supposed to do, step by step.
Have you done that? What are the steps you need to take to find the first string.
Your code only changes the variable: two. The other two variables are never changed.i get cat catch catch
like i used the if statement for example for the first word:
if(first.compareToIgnoreCase(second) < 0 && first.compareToIgnoreCase(third) > 0) { two=first; } if(first.compareToIgnoreCase(second) > 0 && first.compareToIgnoreCase(second) < 0) { two=first; }
PLEASE PLEASE HELP ME ON HOW TO FIX MY PROBLEM
I DON'T WANT TO FAIL
Before you write any code, you need to design the logic for what the code is supposed to do, step by step.
Have you done that? What are the steps you need to take to find the first string the lowest one.
i POSTED WHAT I DID IN MY FIRST POST UP
!
THAT WHAT I DID WITH MY PROGRAM ONLY
+ WE NEVER DESIGN SOMETHING BEFORE WE WRITE A CODE
WE ARE JUST BEGINNERS!
FIRST CLASS OF JAVA!
Time to learn how to program. First you think about the problem, then you design a solution and then you write code.
For example here is a design in pseudo code to find and save the smaller of two ints: one and two
Compare the two ints
if one is smaller than two
smaller = one
else
smaller = two
Now expand that to be for three items
so i do if first = one
else
first=two
else=three??
Sorry that makes no sense.
Why are you testing for equality? To sort you need to know if one value is less than another.
My algorithm started with:
if one is smaller than two
Your names are backwards for me. I think that you read in strings: one, two and three and then sort them so that first has the first in order, second has the second and third has the last(third).
Try writing the logic for finding if one is the lowest of the three strings: one, two, three.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.