| | |
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 |
account android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer homework html ide image inheritance integer integration intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux loop method midlethttpconnection migrate mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program property ria scanner server set sharepoint smart sms smsspam sourcelabs splash sql sqlite subclass support swing testautomation textfield threads tree trolltech unlimited utility windows






