urrgent problem .. please help me
Posted: Wed Mar 01, 2006 8:21 pm
hi everybody
I have problem .. with an algorithm ..
write a code wich read a text and find the number of each repeated element in that text and replace the number with asterisk
ex:
this is a nice day:
a: **
c: *
e:*
h: *
i: ***
and so on
this is the code I write
public class man
{
public static void main (String[] args) throws java.io.IOException
{
java.util.Scanner in = new java.util.Scanner (System.in);
final int NUMCHARS = 33;
int[] lower = new int[NUMCHARS];
char current; //the current character being processed
int nbrSpaces = 0; //counter for non-alphabetics
int nbrPoints = 0;
int nbrSemicolon = 0;
int nbrColon = 0;
int nbrQuestionmark = 0;
int nbruppropstecken = 0;
int nbrRows = 0;
System.out.println ("Enter a sentence:");
String line = in.nextLine ();
// Count the number of each letter occurrence
for (int ch = 0; ch < line.length(); ch++)
{
current = line.charAt(ch);
if (current >= 'a' && current <= 'z')
lower[current-'a']++;
else if (current == ' ')
nbrSpaces ++;
else if
(current == '.')
nbrPoints ++;
else if (current == ';')
nbrSemicolon ++;
else if (current == ',')
nbrColon ++;
else if (current == '?')
nbrQuestionmark ++;
else if (current == '!')
nbruppropstecken ++;
else if (current == '\n')
nbrRows ++;
}
System.out.println ();
for (int letter=0; letter < lower.length;letter++)
{
System.out.print((char)(letter + 'a'));
System.out.println(": " + lower[letter]);
}
System.out.println ();
System.out.println ("blanktecken " + nbrSpaces);
System.out.println ("." + nbrPoints);
System.out.println (";" + nbrSemicolon);
System.out.println ("," + nbrColon);
System.out.println ("?" + nbrQuestionmark);
System.out.println ("!" + nbruppropstecken);
System.out.println ("antalrader" + nbrRows);
}
}
but now .. I can`t find a way to replace the number of repeated element with asterisk
I appreciate your help
![:(](./images/smilies/icon_frown.gif)
I have problem .. with an algorithm ..
write a code wich read a text and find the number of each repeated element in that text and replace the number with asterisk
ex:
this is a nice day:
a: **
c: *
e:*
h: *
i: ***
and so on
this is the code I write
public class man
{
public static void main (String[] args) throws java.io.IOException
{
java.util.Scanner in = new java.util.Scanner (System.in);
final int NUMCHARS = 33;
int[] lower = new int[NUMCHARS];
char current; //the current character being processed
int nbrSpaces = 0; //counter for non-alphabetics
int nbrPoints = 0;
int nbrSemicolon = 0;
int nbrColon = 0;
int nbrQuestionmark = 0;
int nbruppropstecken = 0;
int nbrRows = 0;
System.out.println ("Enter a sentence:");
String line = in.nextLine ();
// Count the number of each letter occurrence
for (int ch = 0; ch < line.length(); ch++)
{
current = line.charAt(ch);
if (current >= 'a' && current <= 'z')
lower[current-'a']++;
else if (current == ' ')
nbrSpaces ++;
else if
(current == '.')
nbrPoints ++;
else if (current == ';')
nbrSemicolon ++;
else if (current == ',')
nbrColon ++;
else if (current == '?')
nbrQuestionmark ++;
else if (current == '!')
nbruppropstecken ++;
else if (current == '\n')
nbrRows ++;
}
System.out.println ();
for (int letter=0; letter < lower.length;letter++)
{
System.out.print((char)(letter + 'a'));
System.out.println(": " + lower[letter]);
}
System.out.println ();
System.out.println ("blanktecken " + nbrSpaces);
System.out.println ("." + nbrPoints);
System.out.println (";" + nbrSemicolon);
System.out.println ("," + nbrColon);
System.out.println ("?" + nbrQuestionmark);
System.out.println ("!" + nbruppropstecken);
System.out.println ("antalrader" + nbrRows);
}
}
but now .. I can`t find a way to replace the number of repeated element with asterisk
I appreciate your help
![:(](./images/smilies/icon_frown.gif)