Results 1 to 11 of 11
Thread: Help please?// Brand new here.
- 12-04-2011, 01:45 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 34
- Rep Power
- 0
-
Re: Help please?// Brand new here.
Use the boolean "or": ||
i.e.,
Java Code:while (foo <= 0 || foo >= 5) { // ... do something ... }
- 12-04-2011, 01:57 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 34
- Rep Power
- 0
Re: Help please?// Brand new here.
Perfect. Thanks!
-
- 12-04-2011, 02:11 AM #5
Member
- Join Date
- Dec 2011
- Posts
- 34
- Rep Power
- 0
Re: Help please?// Brand new here.
Thanks.
I'll be hanging around for while I'd say. Started a course on it not too long ago and ye seem like a helpful bunch!
- 12-04-2011, 02:15 AM #6
Member
- Join Date
- Dec 2011
- Posts
- 34
- Rep Power
- 0
Re: Help please?// Brand new here.
Also while ye'r here can ye help me figure this out. An early attempt of mine at validating on the hairstyle part. Everything else works fine but I cant seem to validate it
Java Code:import java.util.Scanner; public class Mandatory { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner keyboard = new Scanner(System.in); int Mouth, Nose, Eyes,Hair = 0; String MouthString, NoseString, EyesString, HairString = null; System.out.println("Automated Sketch Artist:\n\tPlease make your selections based on the numbers with each \"Style\": "); do { System.out.println("\nHairstyle = 1 Bald, 2 Crew-cut, 3 Curly, 4 Wearing a hat? "); while (! keyboard.hasNextInt()) { System.out.print("Invalid - Try again. Please enter the number which goes with your hairstyle selection. "); keyboard.nextLine(); } switch (Hair) { case 1: HairString = ""; break; case 2: HairString = "----------\n----------"; break; case 3: HairString = "??????????"; break; case 4: HairString = " ______\n/______\\"; break; } Hair = keyboard.nextInt(); keyboard.nextLine(); } while (Hair <= 0 || Hair >4); System.out.println("Eyes = 1 Beedy, 2 Cross-eyed, 3 Glasses, 4 closed? "); Eyes = keyboard.nextInt(); switch (Eyes) { case 1: EyesString = " . . "; break; case 2: EyesString = "(>) (<) "; break; case 3: EyesString = " __ __\n| |-| |\n -- -- "; break; case 4: EyesString = " __ __"; break; default: EyesString = "Invalid "; break; } System.out.println("Nose = 1 Big, 2 Medium, 3 Small? "); Nose = keyboard.nextInt(); switch (Nose) { case 1: NoseString = " | |\n | |\n _ _"; break; case 2: NoseString = " | |\n --"; break; case 3: NoseString = " \\../ "; break; default: NoseString = "Invalid "; break; } System.out.println("Mouth = 1 Moustache, 2 Smiling, 3 Bearded, 4 Frowning? "); Mouth = keyboard.nextInt(); switch (Mouth) { case 1: MouthString = ">>>><<<<\n ==== "; break; case 2: MouthString = "\n (____)"; break; //It's really hard to make a smiley face! So thats as good as I could manage. case 3: MouthString = "\n ====\n ****\n **\n *"; break; case 4: MouthString = "\n ____\n ( )"; break; default: MouthString = "\nInvalid "; break; } System.out.println(HairString); System.out.println(); System.out.println(EyesString); System.out.println(); System.out.println(NoseString); System.out.println(MouthString); System.out.println(); } }
Last edited by Fubarable; 12-04-2011 at 02:22 AM. Reason: QUOTE TAGS CHANGED TO CODE TAGS
-
Re: Help please?// Brand new here.
Moderation note: quote tags changed to code tags in your post above so the code retains its formatting and is readable.
Regarding your problem, what specifically is wrong? Can you elaborate on it?
- 12-04-2011, 02:35 AM #8
Member
- Join Date
- Dec 2011
- Posts
- 34
- Rep Power
- 0
Re: Help please?// Brand new here.
Sorry, as I I'm brand new here
I'll know for next time. Also didnt know posts had to be reveiwed first and assumed I made a mistake so reposted wat I had already.
Well when I run the programme now it works right for the other parts and posts the right mouth nose and eyes but the hair comes up as null all the time. However when I type in bald when asked for hairstyle it does come up asking for the number with the style.
If that makes sense to you?
-
Re: Help please?// Brand new here.
I wonder if you're having problems handling the End Of Line (EOL) token with your Scanner. What if every time you call:
someVariable = keyboard.nextInt();
you follow it with keyboard.nextLine();
to swallow the end of line token. So change this:
Java Code:System.out.println("Eyes = 1 Beedy, 2 Cross-eyed, 3 Glasses, 4 closed? "); Eyes = keyboard.nextInt(); switch (Eyes) {
Java Code:System.out.println("Eyes = 1 Beedy, 2 Cross-eyed, 3 Glasses, 4 closed? "); Eyes = keyboard.nextInt(); keyboard.nextLine(); // *** added *** switch (Eyes) {
- 12-04-2011, 09:34 PM #10
Member
- Join Date
- Dec 2011
- Posts
- 34
- Rep Power
- 0
Re: Help please?// Brand new here.
Thanks! Got it all working out right for me now.
Ye'r quite the helpful bunch around these parts.
-
Similar Threads
-
Brand New To Java, what does it actually do?
By Geslincm in forum New To JavaReplies: 1Last Post: 11-10-2011, 08:14 PM
Bookmarks