Results 1 to 11 of 11
  1. #1
    zeo
    zeo is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Need Help With Assignment

    I'm taking an introductory to java course. I have been completing assignments that are rather basic with if else statements, etc.

    I need some help on where I'm supposed to start off here.

    Here's the assignment

    Write a Java program Search.java to prompt the user to enter an arbitrary string of characters. The program searches for digit characters, and extracts the characters that are digits, and also extracts the characters that are non digits, and provides a count of each.

  2. #2
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    Is this on a window or can you use java.util.Scanner ?

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    When starting an assingment take baby steps.

    Write a class and a main method that does nothing.
    Make sure it compiles (fix errors).
    Move on.
    Get user input and print back to screen.
    Make sure it compiles and runs.
    Iterate over the user input and print one character at a time.
    Make sure it compiles and runs.
    Iterate over the user input and only print the numbers.
    etc

  4. #4
    zeo
    zeo is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    On a window

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Junky is correct. What have you done so far? Follow Junky's steps and let us know which one you got stuck on, what you have so far, and what errors you get.

  6. #6
    zeo
    zeo is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    import javax.swing.*;

    class Search
    {
    public static void main (String [] args)
    {
    String str;

    str = JOptionPane.showInputDialog("Enter String");

    int result = str.length();

    JOptionPane.showMessageDialog(null,
    "String" +result);
    }

    }

    So Far I just need to figure out a way to seperate the characters entered into digits and non digits.

  7. #7
    zeo
    zeo is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Example of How it is supposed to look like
    User enters: hjjkk144

    The message box is supposed to display the following:
    3 Digits: 144
    5 Characters: hjjkk

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Did you move onto the next step I suggested and loop over the String and print each character one at a time?

  9. #9
    zeo
    zeo is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Did you move onto the next step I suggested and loop over the String and print each character one at a time?
    Thats what I'm in the process of doing atm, and I'm completely lost =\

  10. #10
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Did you move onto the next step I suggested and loop over the String and print each character one at a time?
    Nah, use a regex Pattern of "(\d*)(\s*)" and get the returned Matcher's forst and second matches (the digits and the chars, respectively).

  11. #11
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Op is struggling with loops and if statements. Do you really think they can handle regex at this point.

    Also, if this work will be marked I bet the teacher will know if they use regex it isn't their code and fail them.

Similar Threads

  1. Need help with a HW assignment
    By mackavelirip in forum New To Java
    Replies: 4
    Last Post: 02-17-2011, 01:36 AM
  2. assignment help
    By esallender in forum New To Java
    Replies: 4
    Last Post: 10-25-2010, 12:10 PM
  3. GUI First Assignment-DUE 8/1/08
    By ljk8950 in forum AWT / Swing
    Replies: 2
    Last Post: 08-01-2008, 04:23 AM
  4. First GUI Assignment
    By ljk8950 in forum New To Java
    Replies: 1
    Last Post: 07-31-2008, 07:29 AM

Posting Permissions

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