Many thanks for your advices, replaceAll() does work properly,
thus could you give a look to this code for me.
- I would like to output in a JTextArea this format:
Number Frequency
Occurences Percentage
a: 23 18%
this is an Example of string in output utilising the java program bellow.
/**
* performPatternAnalyse Method
*
*/
public void performPatternAnalyse ( int passedToggle )
{
HashMap myFrequency = new HashMap ();
Integer ctrCount = 0;
Integer myFinalCTR_1 = 0;
Integer myFinalCTR_2 = 0;
Integer myPercent_1 = 0;
Integer myPercent_2 = 0;
String analyse1 = "";
String analyse2 = "";
String analyse3 = "";
if ( passedToggle == 1 )
{
char [] myChars = displaySwapTA_4_2.toCharArray ();
for ( int ctr = myChars.length-1; ctr >= 0; ctr-- )
{
Character theCharacter = new Character ( displaySwapTA_4_2.charAt ( ctr ) );
ctrCount = ( Integer ) myFrequency.get ( theCharacter );
if ( ctrCount == null )
{
myFrequency.put ( theCharacter, new Integer ( 1 ) );
}
else {
myFrequency.put ( theCharacter, new Integer ( ctrCount.intValue () +1 ) );
myFinalCTR_1 += ctrCount.intValue () +1;
}
}
Iterator myIter = myFrequency.keySet ().iterator ();
Object myCharKey;
displayOutput4.setText ( ("------ Text First Analysed ------\n") +
( " Name:\t\t" + "Frequency"+ "\n" ) +
( "\tOccurences\t" + "Percentage"+ "\n" ) );
while ( myIter.hasNext () )
{
myCharKey = myIter.next ();
myPercent_1 = ( ( ctrCount * 100 ) / myFinalCTR_1 );
displayOutput4.append ( " " + myCharKey + " :\t" + myFrequency.get ( myCharKey )
+ "\t\t" + myPercent_1 + "\n" );
}
toggleAnalyse = 2;
}
else if ( passedToggle == 2 ) {
char [] myChars = displaySwapTA_4_3.toCharArray ();
for ( int ctr = myChars.length-1; ctr >= 0; ctr-- )
{
Character theCharacter = new Character ( displaySwapTA_4_3.charAt ( ctr ) );
ctrCount = ( Integer ) myFrequency.get ( theCharacter );
if ( ctrCount == null )
{
myFrequency.put ( theCharacter, new Integer ( 1 ) );
}
else {
myFrequency.put ( theCharacter, new Integer ( ctrCount.intValue () +1 ) );
myFinalCTR_2 += ctrCount.intValue () +1;
}
}
Iterator myIter = myFrequency.keySet ().iterator ();
Object myCharKey;
displayOutput4.append ( ( "\n" + "------ Text Second Analysed ------\n") +
( " Name:\t\t" + "Frequency"+ "\n" ) +
( "\tOccurences\t" + "Percentage"+ "\n" ) );
while ( myIter.hasNext () )
{
myCharKey = myIter.next ();
myPercent_2 = ( ( ctrCount * 100 ) / myFinalCTR_2 );
displayOutput4.append ( " " + myCharKey + " :\t" + myFrequency.get ( myCharKey )
+ "\t\t" + myPercent_1 + "\n" );
}
toggleAnalyse = 0;
}
else {
Toolkit.getDefaultToolkit ().beep ();
JOptionPane.showMessageDialog ( null, "Please First Enter the Text to Analyse... ",
" Information Message ",
JOptionPane.INFORMATION_MESSAGE );
toggleAnalyse = 0;
setCursor ( null );
} // End for If-Else
} // End performPatternAnalyse Method
The Analyse works properly, but I've got aproblem
withe the percentage result: 0...
Could someone gives some little helps...Many thanks All.
[pre/]