Results 1 to 7 of 7

Thread: Help!!

  1. #1
    GeeKunMow is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default Help!!

    I'm fairly new to Java, so I need help with even the most basic things ever...

    I need to design and implement an application that reads a string from the user and prints it one character per line using the while statement. Can someone please help me??

    Edit: I'm working from the Java Software Solutions for AP Computer Science A 2nd Edition book. This problem is #3.5 from the programming projects section in Chapter 3. I have to figure out the length of the string the user inputs ( int length (); ??) and something to track what character I'm on ( charAt ??).

    I have this so far (the comments are the requirements my teacher put in):

    import java.util.Scanner;

    public class StringDown
    {
    public static void main (String[] args)
    {
    int count = 0;
    Scanner scan = new Scanner (System.in);

    //Welcome message
    System.out.println ("Welcome to StringDown! Input your string here: ");

    //take in user string
    String sentence = scan.nextLine();

    //Find the number of characters in the string
    int length ();
    //condition is as long as there are characters left in the String

    while ( )

    {

    //pull out that particular letter and println it

    }


    }
    }
    Last edited by GeeKunMow; 10-03-2008 at 04:24 PM.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Yes, we can assist you with get-going efforts. We need to know what books you are working from and what your goals are.

    String newString = new String( user_input );

    Canot go past that until we see how you are going about it, probably for today just read the books, ask questions on matters you do not easily grasp on second or third attempt.

    Be prepared to invest long period of contemplation, Coffee - premium grade.

    Code, not so good for awhile.

    newbies, oh the fun!
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    jack239 is offline Member
    Join Date
    Jul 2008
    Posts
    35
    Rep Power
    0

    Default

    You can refer to this article: Reading user input in java - Java -
    If you still need any help do let me know. I can explain you.

  4. #4
    GeeKunMow is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    I'm not sure how to use the loops and how to track the characters. I'm just confused about concepts basically...

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default

    Do you have a text book? What does it say about loops? You'll need a good text to get an understanding of basic concepts.
    To learn about some technique, write a very simple program that only uses that techique, add some println() statements to it that show how execution is flowing and how the variables are changing and play with it a while. You'll come to see how it works.
    When you have problems, come here with your code and questions.

  6. #6
    jack239 is offline Member
    Join Date
    Jul 2008
    Posts
    35
    Rep Power
    0

    Default

    Very simple. From the user entry you got the String sentence. For length print the size as sentence.length();
    New to Java/PHP/Javascript development?
    For free help go to- www.techcubetalk.com

  7. #7
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Post off by one

    Quote Originally Posted by GeeKunMow View Post
    I'm fairly new to Java, so I need help with even the most basic things ever... I have this so far - the comments are the requirements my teacher put in -
    Okay;
    Java Programming, 2nd Edition by J.Farrell (Thomson). Objects-first, GUI-first approach. Many examples in tutorial style.
    source:Books on Java
    I mostly use the comments as a fast and handy editor, sometimes helpful notes can be read or left there but on large projects code is self-documenting and people are too scared to put jokes in them so it's mostly a tool for instructors to clue you on what's going on. Try to use the instructor's trail left in the comment as a study guide into what chapters in the book and what websites you will be productive on, the other poster's have this nailed but I ask you not - really, not - to distract from the instructor's comments in the comments because of trying to do character / byte conversion. There are several approaches here, my first and obvious would be to do int length = string.length(); and do some arithmetic on the in. Another approach would be to pass the chars into a collection, then do method calls on the collection. Another would be to do is as while string.position is not at end or beginning of string, increment count or print the character to a file or System standard console or possibly get taken down by a deep discussion on data structures that will never end - it's a matter of what your approach is in general to things in general and whether you want to focus on GUI and Objects vis-a-vis how the machine actually runs.

    Do you intend to make a work of cs studies or is this ancillary to other discipline? We need to chart a cybercartography that is not off by one on long term series.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Posting Permissions

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