Solve this problems for me, any help will be appreaciated


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Solve this problems for me, any help will be appreaciated

  1. #1
    Join Date
    Aug 2004
    Posts
    6

    Solve this problems for me, any help will be appreaciated

    Design, write in Java, test and document a program (application) that accepts a short (i.e. less
    than 20 character) string from the user and prints it out on the screen in a certain pattern. In
    response to the user keeping pressing enter, the program moves it across the page to bounce off
    column 20 and return. Then the program terminates. Use “*” characters to fill in the unused
    columns.
    For example, suppose that the user enters “dipsy”. Here is the output; each line of output is in
    response to the user pressing the “enter” key.
    Please enter your string: dipsy
    dipsy**************
    *dipsy*************
    **dipsy************
    ***dipsy***********
    ...etc ...
    *************dipsy*
    **************dipsy
    *************dipsy*
    ************dipsy**
    ...etc...
    *dipsy*************
    dipsy**************
    Program terminated.

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    So what exactly is your problem? If you're more specific then we can help, but we're not going to write it all for you :P

  3. #3
    Join Date
    Aug 2004
    Posts
    6
    well,

    I decided to use stringbuffer to approach the question but i have trouble moving the word "dipsy" to the right and back again...

    Please help


    thanks

  4. #4
    Join Date
    Feb 2004
    Posts
    541
    Well to move the word dipsy to the right you add something to the beginning of the string (add a space if you don't want it to be seen). To move it back again you take something away from the beginning.

    The way I would do it would be to write a method that repeatedy prints out a line of spaces followed by the word. Each time it runs it will print out an extra space. To move it back write another method that starts off with a large number of spaces then prints one less each time.

  5. #5
    Join Date
    Aug 2004
    Posts
    6
    PHP Code:

    //THIS IS A JAVA CODE
    public class fill
    {
      public static 
    void main(String[] args)
      {
        
    String input = new String();
        
    StringBuffer buffer = new StringBuffer();
        
    int startdexfinishdex;

        do {
          
    System.out.print("Please enter a string (no more than 20 characters): ");
          
    input SavitchIn.readLine();
        }while (
    input.length() > 20); //Loop again if string.length is more than 20

        
    buffer.append(input); //append String to StringBuffer
        
    buffer.setLength(20); //create buffer to store 20 characters

        
    startdex 0;
        
    finishdex input.length() - 1;

        
    //int counter=buffer.length()-input.length();
        //int maincount =0;
        //for(int maincount=0 ;maincount < 9 ;maincount++) {
        
        
    int counter 0;  //TRYING TO USE A LOOP TO INCREMENT THE COUNTER BUT FAILED

        
    do {
          for (
    int count1 startdexcount1 <= countercount1++) { //check start
            
    char fill '*';
            
    buffer.setCharAt(count1fill);
          }

          for (
    int counter2 finishdex countercounter2 buffer.length(); counter2++) { //check finish
            
    char fill '*';
            
    buffer.setCharAt(counter2fill);
          }

          for (
    int count startdexcount <= finishdexcount++) { //fill word

            
    buffer.setCharAt(counterinput.charAt(count));
            
    counter++;
          }

          
    input buffer.toString();
          
    System.out.println("Filled: " +input);

          
    counter++;
        }while(
    counter<9);
      }



    I tried using the above code, well having several problems , if you look carefully int counter = 0; when if change the value of the counter,let says to 2 , then the output will be
    **dispy***************

    then i tried to use a for loop to increment the counter.... but it faled

    Please help out....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center