Results 1 to 10 of 10
  1. #1
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Unhappy I need some Loop help

    Hello, I'm really new to programming and i need some help or clarification. I need to generate an if loop where for example a variable = aa123 ( letter, letter, number, number, number) and it has to return an error code. I have been hitting my head against the wall with this... any help would be appreciated!!!!

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

    Default Re: I need some Loop help

    Quote Originally Posted by cloverrea View Post
    Hello, I'm really new to programming and i need some help or clarification. I need to generate an if loop where for example a variable = aa123 ( letter, letter, number, number, number) and it has to return an error code. I have been hitting my head against the wall with this... any help would be appreciated!!!!
    Some suggestions:
    • Give us a more complete description of your requirement.
    • Show us what you've done so far.
    • Tell us the precise problems that your current code is having -- compilation problems? behavior problems?
    • If you see error messages from your code, show us the complete message
    • Ask as specific a question as possible. Overly general questions are often best answered by referral to the tutorials while very specific questions usually get specific answers.

  3. #3
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Default Re: I need some Loop help

    Okay, okay so here is what I have done.... I know it is completely wrong but I hope you can see what I'm trying to do...

    String itemNumberString = System.out.println("Enter Item Number: ");
    int itemNumber = Integer.parseInt(itemNumberString);

    char char1 =
    char char2 =
    int number1 = 0;
    int number2 = 0;
    int number3 = 0;
    public static editItemNum(int itemNumber);
    if (itemNumber > 5)
    System.out.println("**ERROR** - Item number must be five characters");
    else if (char1 is digit())
    System.out.println("**ERROR** - Item number must start with two letters ");
    else if (char2 is digit())
    System.out.println("**ERROR** - Item number must start with two letters ");
    else if (number1 != digit())
    System.out.println("**ERROR** - Item number must be numeric last three spaces ");
    else if (number2 != digit())
    System.out.println("**ERROR** - Item number must be numeric last three spaces ");
    else if (number3 != digit())
    System.out.println("**ERROR** - Item number must be numeric last three spaces ");




    AHHHHH lol I'm so lost....

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

    Default Re: I need some Loop help

    You're still leaving out information. Please re-read my recommendations and also check out my link on how to ask smart questions shown below.

  5. #5
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Default Re: I need some Loop help

    I'll try again I need to prompt the user to enter an Item number. The Item number must be two letters followed by three number for example itemNumber= aa123. I then need to loop it so that if the first or second characters are not letters, I display an error message or if the last three numbers are not numbers I display an error message. After if the item number is all correct, I prompt the user for a description. This is what I have done so far

    public class Question2
    {
    public static void main (String[] args);
    Scanner input = new Scanner(System.in);

    String itemNumberString = System.out.println("Enter Item Number: ");
    int itemNumber = Integer.parseInt(itemNumberString);

    char char1 =
    char char2 =
    int number1 = 0;
    int number2 = 0;
    int number3 = 0;
    public static editItemNum(int itemNumber);
    if (itemNumber > 5)
    System.out.println("**ERROR** - Item number must be five characters");
    else if (char1 is digit())
    System.out.println("**ERROR** - Item number must start with two letters ");
    else if (char2 is digit())
    System.out.println("**ERROR** - Item number must start with two letters ");
    else if (number1 != digit())
    System.out.println("**ERROR** - Item number must be numeric last three spaces ");
    else if (number2 != digit())
    System.out.println("**ERROR** - Item number must be numeric last three spaces ");
    else if (number3 != digit())
    System.out.println("**ERROR** - Item number must be numeric last three spaces ");


    It will not compile, mainly because I don't know how to initialize the variables and the compiler tells me that '.class' is expected after the word char. I really need help with the loop statement as well as how to initialize the variables. I haven't come across a variable where you include numbers and characters before so I'm just very confused. I have a feeling that I am declaring unnecessary variables. Please help me!

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

    Default Re: I need some Loop help

    Yikes, you're right, everything is wrong here starting with no true main method, but certainly not ending there. Your best chance to learn this is to hit the tutorials to see how to create a main method (note examples of this and how they use curly braces to hold everything). You'll want to see how to use a Scanner object since System.out.println(...) doesn't return anything much less a String. Start here:

    The Java Tutorials

  7. #7
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Default Re: I need some Loop help

    haha thank you!!!! I will head there right now

  8. #8
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default Re: I need some Loop help

    I guess you have to use filter in each character, you could use charAt() to determine to get a specific character then use a character.isLetter or character.isDigit to determine if it is digit or letter

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

    Default Re: I need some Loop help

    Quote Originally Posted by RichersooN View Post
    I guess you have to use filter in each character, you could use charAt() to determine to get a specific character then use a character.isLetter or character.isDigit to determine if it is digit or letter
    I think first he has to learn to create a compilable main method, and get user input from Scanner. Then he can work on massaging the input once he's gotten it.

  10. #10
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Default Re: I need some Loop help

    just reading through these tutorials and I have a quick question if what I have to return has characters and numbers can it be classified as int in the main method? I can't seem to find the answer to this...
    Last edited by cloverrea; 10-11-2011 at 05:12 AM.

Similar Threads

  1. Replies: 1
    Last Post: 10-01-2011, 03:12 AM
  2. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 06:46 PM
  3. [Q] Loop issue (while loop)
    By iriscience in forum New To Java
    Replies: 9
    Last Post: 01-31-2011, 05:21 PM
  4. Convert do while loop to for loop
    By sandeeptheviper in forum New To Java
    Replies: 3
    Last Post: 01-03-2011, 01:37 PM

Tags for this Thread

Posting Permissions

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