| | |
Bubble sorting
![]() |
•
•
Join Date: Aug 2008
Posts: 6
Reputation:
Solved Threads: 0
hello, guys i have a really stupid problem about characters and string; i dont know which to use. wacko.gif
iam bubble sorting for example a name:
input:
dreamincode
output:
a c d d e e i m n o
why does my code in error? my compiler saids the ff:
i try my hardest but as if i try the more error i get.
i try to simplify the error like this short so it wouldn't be so complicated.
can you please help me??
i really need your help.
Thnks so much
iam bubble sorting for example a name:
input:
dreamincode
output:
a c d d e e i m n o
why does my code in error? my compiler saids the ff:
Java Syntax (Toggle Plain Text)
Exception in thread "main" java.lang.Error: Unresolved compilation problems: The local variable characterArray may not have been initialized The local variable characterArray may not have been initialized The local variable characterArray may not have been initialized at BubbleSort.main(BubbleSort.java:15)
i try my hardest but as if i try the more error i get.
i try to simplify the error like this short so it wouldn't be so complicated.
Java Syntax (Toggle Plain Text)
import java.util.Arrays; import java.io.*; public class BubbleSort { /** * @param args */ public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); char characterArray[]; System.out.print("Enter Name:\t"); Arrays.sort(characterArray); for (int i = 0; i < characterArray.length; i++) { System.out.print(characterArray[i]); System.out.print(", "); } } }
can you please help me??
i really need your help.
Thnks so much
Last edited by qaz1134; Sep 13th, 2008 at 1:50 pm.
You need to initialize your character array something like this:-
where the "charArraySize" implies the dimension for your array, you can replace it with 10,20, 30 or ask the user to input it.
Also how come I do not see the line where you are taking the input from the console ??
java Syntax (Toggle Plain Text)
char characterArray[] = new char[charArraySize];
where the "charArraySize" implies the dimension for your array, you can replace it with 10,20, 30 or ask the user to input it.
Also how come I do not see the line where you are taking the input from the console ??
Last edited by stephen84s; Sep 13th, 2008 at 2:06 pm.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
•
•
Join Date: Aug 2008
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
You need to initialize your character array something like this:-
Also how come I do not see the line where you are taking the input from the console ??
and oh! by the way do is still need to use string ???
because BufferedReader Only reads as String right? so how can i make the string be character..
for example iam declaring an integer:
Java Syntax (Toggle Plain Text)
String = input; int num; System.out.print("******"); num = Integer.parseInt (input = in.readLine());
how can i make it like a character or should i declare a character directly with out declaring a string???
and
if the array is 20 should i write it this way?
java Syntax (Toggle Plain Text)
char characterArray[20] = new char[charArraySize];
iam kinda lost please help further explanation.
I said
I had said replace "charArraySize" with the appropriate size.
So if your array size is 20 it should be:-
And no BufferedReader can also read a character at a time. Refer here for more details on that.
Heres the javadocs of the String class of Java, it provides a function to export the data in a given String to a char array directly, so you wouldn't even have to initialize the char array the way we have discussed anyways.
java Syntax (Toggle Plain Text)
char characterArray[] = new char[charArraySize];
So if your array size is 20 it should be:-
java Syntax (Toggle Plain Text)
char characterArray[] = new char[20];
And no BufferedReader can also read a character at a time. Refer here for more details on that.
Heres the javadocs of the String class of Java, it provides a function to export the data in a given String to a char array directly, so you wouldn't even have to initialize the char array the way we have discussed anyways.
Last edited by stephen84s; Sep 13th, 2008 at 2:51 pm.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
![]() |
Similar Threads
- Link List Sorting Problem (C++)
- bubble sorting in an array (C)
- help by sorting a simply linked list (C)
Other Threads in the Java Forum
- Previous Thread: Timing of the word
- Next Thread: Noob and unsure
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character chat class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list loops mac map method methods mobile netbeans newbie notdisplaying number online printf problem program programming project properties qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor






