Results 1 to 1 of 1
- 04-02-2011, 01:57 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 13
- Rep Power
- 0
How do I check if the character in an array matches...?
For the countBase method I need to check if the base passed, in this case 'A' matches the letter in all the positions in the arrays...that way the other methods will output correctly. And then return a filled array with the totals. I only need help starting out the countBase method, everything else is finished..
Thanks! And I know it's wrong, I just don't know how to start it.. :S
Java Code:import java.io.*; import java.util.*; public class Lab6 { public static void main(String[] args) throws FileNotFoundException { Scanner inFile = new Scanner(new File("seq.txt")); //text data file with DNA bases char base = 'A'; //base passed to countBase method int size = 8; //size of the arrays char[] array1 = new char[size]; //first array with 8 indexes char[] array2 = new char[size]; //second array with 8 indexes char[] array3 = new char[size]; //third array with 8 indexes char[] array4 = new char[size]; //fourth array with 8 indexes int i = 0; while(inFile.hasNext()) { array1[i] = inFile.next().charAt(0); array2[i] = inFile.next().charAt(0); array3[i] = inFile.next().charAt(0); array4[i] = inFile.next().charAt(0); i++; } System.out.println(array1); System.out.println(array2); System.out.println(array3); System.out.println(array4); int[] result = countBase(array1, array2, array3, array4, base); int mostIndex = findMost(result); double average = computeAvg(result); System.out.println(result); System.out.println("The largest value in the counter array is " + result[mostIndex]); System.out.println("The average for the counter array is " + average); } public static int[] countBase(char[] one, char[] two, char[] three, char[] four, char letter) //count number of times a base appears { int counter = 0; int index = 0; if(one[index] == letter) { counter++; } int[] base = new int[counter]; return base; } public static int findMost(int[] counter) //find index position of largest element { int largeIndex = 0; for(int i = 0; i < counter.length; i++) { if(counter[i] > counter[largeIndex]) { largeIndex = i; } } return largeIndex; } public static double computeAvg(int[] counter) //compute average { int sum = 0; for(int i = 0; i < counter.length; i++) { sum = sum + counter[i]; } double avg = (double)(sum) / counter.length; return avg; } }
Similar Threads
-
searching char array with another char array for full word matches
By karunabdc in forum New To JavaReplies: 2Last Post: 03-08-2011, 06:20 AM -
Cant print character array in applet
By nathancz in forum Java AppletsReplies: 3Last Post: 03-02-2011, 06:44 PM -
Using a character array with html
By ishdevil in forum New To JavaReplies: 0Last Post: 02-10-2010, 01:01 PM -
How to check if character is 7 bit or 16 bit?
By markthien in forum Advanced JavaReplies: 2Last Post: 07-29-2009, 08:26 AM -
comparing array using character
By Anseki in forum New To JavaReplies: 7Last Post: 10-03-2008, 07:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks