Overclock.net banner

1 - 4 of 4 Posts

·
Registered
Joined
·
1,028 Posts
Discussion Starter #1
Here is exactly what the teacher gave us(scanned)<br />
<div style="margin:20px; margin-top:5px; ">
<div class="smallfont" style="margin-bottom:2px">Quote:</div>
<table cellpadding="6" cellspacing="0" border="0" width="99%">
<tr>
<td class="alt2" style="border:1px inset">

<a href="http://imageshack.us" target="_blank"><img src="http://img179.imageshack.us/img179/7161/scan10001largevy1.jpg" border="0" alt="" onload="NcodeImageResizer.createOn(this);" /></a><br />
<a href="http://img224.imageshack.us/my.php?image=scan10001na4.jpg" target="_blank"><img src="http://img224.imageshack.us/img224/4342/scan10001na4.th.jpg" border="0" alt="" onload="NcodeImageResizer.createOn(this);" /></a>

</td>
</tr>
</table>
</div>here is what I did, I need help with everything else<img src="/images/smilies/rolleyes.gif" border="0" alt="" title="Roll Eyes (Sarcastic)" class="inlineimg" /><br />
<br />
<div style="margin:20px; margin-top:5px; ">
<div class="smallfont" style="margin-bottom:2px">Quote:</div>
<table cellpadding="6" cellspacing="0" border="0" width="99%">
<tr>
<td class="alt2" style="border:1px inset">

//Name: Petr Charouz<br />
//Date: 10/9/2006<br />
<br />
import java.util.Scanner;<br />
<br />
public class CountLetters{<br />
<br />
public static void main(String[] args){<br />
<br />
int a = 0;<br />
int b = 0;<br />
int c = 0;<br />
int d = 0;<br />
int e = 0;<br />
int f = 0;<br />
int g = 0;<br />
int h = 0;<br />
int i = 0;<br />
int j = 0;<br />
int k = 0;<br />
int l = 0;<br />
int m = 0;<br />
int n = 0;<br />
int o = 0;<br />
int p = 0;<br />
int q = 0;<br />
int r = 0;<br />
int s = 0;<br />
int t = 0;<br />
int u = 0;<br />
int v = 0;<br />
int w = 0;<br />
int x = 0;<br />
int y = 0;<br />
int z = 0;<br />
<br />
<br />
<br />
<br />
}<br />
<br />
}<br />
<br />
}

</td>
</tr>
</table>
</div>
 

·
Registered
Joined
·
336 Posts
You should have been able to create a simple loop to assign those variables. Java comes with a built in string parser which would disassemble a string into components that can be looped - you can also id the length of the string (built in function) to determine the loop length. Then you just need to get the int value of the letter for identification and increase the appropriate variable.<br />
<br />
Good luck!
 
  • Rep+
Reactions: pcharouz

·
Registered
Joined
·
210 Posts
Yeah each character has a number. Figure out what it is (I think 'a' is 48), then:<br />
<br />
int[] letters = new int[26]; //java sets everything to zero already<br />
<br />
//set the string to lowercase<br />
<br />
//loop thru each letter of the string, like for (int i = 0; ...... and do this for each one:<br />
letters[((int)string.charAt(i))-48]++;
 
  • Rep+
Reactions: pcharouz

·
Registered
Joined
·
1,028 Posts
Discussion Starter #4
Thanks, but its too late now, the homework was due yesterday. But I stayed there after school, and the teacher helped me.
 
1 - 4 of 4 Posts
Top