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

    Default Prompt algorithm

    Input file:
    Java Code:
    ddd
    bbb
    ccc
    aaa
    bbb
    aaa
    bbb
    output file:
    Java Code:
    bbb -3
    aaa - 2
    duplicate lines, indicating the number of repetitions
    what algorithm?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    You might want to see the link in my signature on asking smart questions. How would you do this by hand, with a piece of paper and a pencil and no computer? Write that out, and there's your algorithm.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    eIO
    eIO is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    ??
    I can not think of an algorithm(

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    We aren't going to think of it for you, that's not really how this works.

    Think about it logically- write this out on a piece of paper, and solve it. How did you do it? How did you come up with the expected output in your original post? Think about it step by step.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,329
    Rep Power
    25

    Default

    To start: write a small program that reads in the input file and prints its contents to the screen.

  6. #6
    eIO
    eIO is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Java Code:
    class SortString 
    {
    	static String arr[] = 
        {"ddd", "sss", "    aaa", "ggg", " aaa ", "bbb",    
         "ddd", "ccc",  };
    
      public static void main(String args[]){
      for(i=0;i<=arr.length;i++){
      System.out.println(""+arr[i]);
    }
    }
    }

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,329
    Rep Power
    25

    Default

    That will do for testing.
    Now how are you going to count the repetition of each String?

  8. #8
    eIO
    eIO is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Java Code:
    class SortString 
    {
    	static String arr[] = 
        {"ddd", "sss", "    aaa", "ggg", " aaa ", "bbb",    
         "ddd", "ccc",  };
    
      public static void main(String args[]){
      for(i=0;i<=arr.length;i++){
      System.out.println(""+arr[i]);
    
    int k = o;
      for(j=0;j<=arr.length;j++)
    {if (arr[0].equals(arr[j]))
      //counter
     k++;//or
     k=k+1;// i do not know((
    }
    int p = o;
      for(j=0;j<=arr.length;j++)
    {if (arr[1].equals(arr[j]))
      //counter
     p++;//or
     p=p+1;// i do not know((
    }
    //etc
    }
    }

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,329
    Rep Power
    25

    Default

    Before you try to write code, you need to design what the code is supposed to do.
    Can you explain the steps your code will need to take to solve your problem?

  10. #10
    eIO
    eIO is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Java Code:
    int k=o;
    for(i=0;i<=arr.length;i++){
         for(j=0;j<=arr.length;j++){
              if(arr[i].equals(arr[j])) {
                  g=g+1;          \\after each comparison, increment counter
                              }
                System.out.println(g);          \\print count after all the iterations of the j
                System.out.println(arr[i]);            \\print the current element
          } \\ след. i = 1 и т.д.
    }
    Console
    Java Code:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
    at SortString.main(gg.java:91)

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,329
    Rep Power
    25

    Default

    Before you try to write code, you need to design what the code is supposed to do.
    Can you explain the steps your code will need to take to solve your problem?

    What is the size of the array at line 91? The index value of 7 is past the end of the array.

Similar Threads

  1. RE: JOptionPane Prompt
    By bleh in forum New To Java
    Replies: 3
    Last Post: 02-13-2011, 02:54 PM
  2. New Command prompt
    By jmga9 in forum New To Java
    Replies: 4
    Last Post: 11-10-2010, 01:53 AM
  3. Replies: 4
    Last Post: 03-25-2010, 04:47 PM
  4. Jcreator to DOS Prompt
    By arshesander in forum New To Java
    Replies: 5
    Last Post: 02-17-2010, 06:25 AM
  5. help me!!!! about command prompt..
    By kureikougaiji in forum New To Java
    Replies: 2
    Last Post: 11-13-2008, 06:15 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
  •