Results 1 to 11 of 11
Thread: Prompt algorithm
- 07-14-2011, 04:58 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 10
- Rep Power
- 0
- 07-14-2011, 05:09 PM #2
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!
- 07-14-2011, 05:15 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 10
- Rep Power
- 0
??
I can not think of an algorithm(
- 07-14-2011, 05:19 PM #4
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!
- 07-14-2011, 06:21 PM #5
To start: write a small program that reads in the input file and prints its contents to the screen.
- 07-14-2011, 06:37 PM #6
Member
- Join Date
- Jul 2011
- Posts
- 10
- Rep Power
- 0
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]); } } }
- 07-14-2011, 06:41 PM #7
That will do for testing.
Now how are you going to count the repetition of each String?
- 07-14-2011, 07:12 PM #8
Member
- Join Date
- Jul 2011
- Posts
- 10
- Rep Power
- 0
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 } }
- 07-14-2011, 07:20 PM #9
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?
- 07-14-2011, 11:15 PM #10
Member
- Join Date
- Jul 2011
- Posts
- 10
- Rep Power
- 0
ConsoleJava 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 и т.д. }Java Code:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at SortString.main(gg.java:91)
- 07-14-2011, 11:34 PM #11
Similar Threads
-
RE: JOptionPane Prompt
By bleh in forum New To JavaReplies: 3Last Post: 02-13-2011, 02:54 PM -
New Command prompt
By jmga9 in forum New To JavaReplies: 4Last Post: 11-10-2010, 01:53 AM -
How to cause a second prompt to run after the first.
By G-Unit in forum New To JavaReplies: 4Last Post: 03-25-2010, 04:47 PM -
Jcreator to DOS Prompt
By arshesander in forum New To JavaReplies: 5Last Post: 02-17-2010, 06:25 AM -
help me!!!! about command prompt..
By kureikougaiji in forum New To JavaReplies: 2Last Post: 11-13-2008, 06:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks