Originally Posted by
simplemind
Ok. So its given a string that's 70 characters long. Every character in the string is either an 'A' or a 'B'. There are 4 categories. These categories are broken up in that starting from the first character every seventh character corresponds with the first category. The second category (the only one I posted) starts at the second character, but it also includes the third character. Then every seventh character after the second character and every seventh character after the third character are in the second category. Third and 4th categories are just like the second however they start at 4 and 6.
Global A,B Counter did nothing
Counter did even less since every character is A/B
Code:
public static int sN(Scanner read)
public static int sN(Scanner read)
{
char currentCharacter = '0';
int ACount = 0;
int BCount = 0;
while(read.hasNextLine())
{
String s = read.next();
for(int str = 1; str < s.length(); str+=7)
{
ACount = ACount + charComparision(s.charAt(str), 'a');
BCount = BCount + charComparision(s.charAt(str), 'b');
}
for(int str = 2; str < s.length(); str+=7)
{
ACount = ACount + charComparision(s.charAt(str), 'a');
BCount = BCount + charComparision(s.charAt(str), 'b');
}
}
double sNAverage = ((counterB/(counterA + counterB))*100);
int sNPercent = (int)(sNAverage + 0.5);
return sNPercent;
}
public static int charComparision(char src, char cmp){
char tmpsrc = Character.toUpperCase(src);
char tmpcmp = Character.toUpperCase(cmp);
if (src == cmp) return 1;
return 0;
}
You could also do the whole Count for all 4 Categories in 1 loop