Results 21 to 29 of 29
- 05-30-2010, 12:52 AM #21
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Look, next time you start writing something, do it in pseudo code. That is, don't write java, but just plain language and detail the steps you need to take. In your case, it looks like this:
Once you have the steps laid out, it's much easier to write up your program.Java Code:prompt user to input word if word is stop exit the program if word contains secret letter print out Success else print out Fail repeatEver seen a dog chase its tail? Now that's an infinite loop.
- 05-30-2010, 01:01 AM #22
Member
- Join Date
- May 2010
- Posts
- 24
- Rep Power
- 0
the problem is am a begginer i cant implement this thing into the program
sorry for that guyz
- 05-30-2010, 01:06 AM #23
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
No, the thing is you don't want to try. The steps I laid out in the above post make it painfully obvious what needs to be done, and the code you posted a while back has almost all the necessary elements in it. Look, here take it:
I put the code in white color in the slim chance you'll try and write the few lines of code required by yourself. Copy/paste the code above, and you're only harming yourself in the long run.Java Code:[COLOR="White"]import java.util.Scanner; public class Guess { public static void main(String[] args) { char guess = 'r'; String input; Scanner sc = new Scanner(System.in); while(true) { System.out.println("Input word"); input = sc.next().toLowerCase(); if(input.equalsIgnoreCase("stop")) break; if(input.indexOf(guess) != -1) System.out.println("Your guess contains secret"); else System.out.println("Your guess doesn't contain secret"); } } }[/COLOR]Ever seen a dog chase its tail? Now that's an infinite loop.
- 05-30-2010, 01:20 AM #24
Member
- Join Date
- May 2010
- Posts
- 24
- Rep Power
- 0
thank you very much .. i've tried it this way by the way " just because i want to tell you that i've tried"
Java Code:public static void main(String[] args) { Scanner sc; char hidden = 'R'; String guess; String ab="stop"; sc = new Scanner(System.in); do { System.out.println("enter the word"); guess = sc.nextLine().toUpperCase(); if (guess==ab) { System.exit(0) } } while (guess.indexOf(hidden) == -1); System.out.println("Well done"); } }Last edited by zohdi; 05-30-2010 at 01:33 AM.
- 05-30-2010, 01:33 AM #25
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Don't use == to compare Strings. (This was probably covered in your class, so check your notes and your text -- there is a method in the String class that enables you to check if a String has the same text as another String.) And when you're posting to the forum, please put your code in CODE tags, and explain your problem clearly. "Here is my code, and the program doesn't stop when I enter 'stop'" is a much better question to post than "I don't know how to do it."Java Code:if (guess==ab)
There is no need to apologize for being a beginner -- we were all beginners once, and in many, many areas, we still are. But try to clearly identify exactly what help you need, and ask a clear question. Presumably you are taking this course because you want to become a Java programmer. As a Java programmer, there will always be things you don't know, and you will need to research to find the answer, or ask for help. Knowing how to ask for help is an important skill. Asking other people to do your work for you is rarely a good technique (unless you are paying them to work for you).
-Gary-
- 05-30-2010, 01:35 AM #26
Member
- Join Date
- May 2010
- Posts
- 24
- Rep Power
- 0
thank you garry
- 05-30-2010, 01:37 AM #27
Member
- Join Date
- May 2010
- Posts
- 24
- Rep Power
- 0
could i use this command to exit
" System.exit(0) "
?
- 05-30-2010, 01:39 AM #28
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
- 05-30-2010, 01:41 AM #29
Member
- Join Date
- May 2010
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
A new thing arrives...
By ewomack in forum IntroductionsReplies: 3Last Post: 10-09-2009, 09:16 PM -
[SOLVED] Simple Trig Thing
By AndrewM16921 in forum New To JavaReplies: 4Last Post: 05-16-2009, 06:45 AM -
What did i do wrong on thing method?
By PureAwesomeness in forum New To JavaReplies: 9Last Post: 03-08-2009, 08:37 AM -
Need help with a simple Java thing involving array of objects
By Jeremy8 in forum New To JavaReplies: 5Last Post: 02-25-2009, 07:14 PM -
PLz i really need help on this final thing
By jason27131 in forum New To JavaReplies: 2Last Post: 08-03-2007, 02:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks