Results 1 to 11 of 11
  1. #1
    GoodThing007 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default Help please?// Brand new here.

    I want to put or in here and cant find it in google?

    while( Number <=0 "OR" Number >=5)

    So simple yet so confused.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help please?// Brand new here.

    Use the boolean "or": ||

    i.e.,

    Java Code:
    while (foo <= 0 || foo >= 5) {
       // ... do something ...
    }
    You can find more information here: Logical Operators in Java

  3. #3
    GoodThing007 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default Re: Help please?// Brand new here.

    Perfect. Thanks!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help please?// Brand new here.

    Quote Originally Posted by GoodThing007 View Post
    Perfect. Thanks!
    You're welcome, and welcome to the Java-Forums.org!

  5. #5
    GoodThing007 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default 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!

  6. #6
    GoodThing007 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default 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

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default 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?

  8. #8
    GoodThing007 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default 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?

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default 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) {
    to this:

    Java Code:
    System.out.println("Eyes =  1 Beedy, 2 Cross-eyed, 3 Glasses, 4 closed?  ");
    Eyes = keyboard.nextInt();
    keyboard.nextLine(); // *** added ***
    switch (Eyes) {

  10. #10
    GoodThing007 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default 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.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help please?// Brand new here.

    You're quite welcome! Look forward to seeing you around.

Similar Threads

  1. Brand New To Java, what does it actually do?
    By Geslincm in forum New To Java
    Replies: 1
    Last Post: 11-10-2011, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •