Hello!
So I'm writing a massive code for a school project at the moment, and while I have all the complicated stuff, I am getting stuck on this simple bit. I'm trying to scan in a text file, a single line of a bunch of characters, then make that file a string, then traverse the string to see if there are any upper case A-G's. My code as it is compiles, and runs, but none of my int counters are going up. Someone this not reading correctly.
Can someone help? This is the last thing I have to do for this
Below is the section of relevant code:
import java.util.*; import java.io.*; import javax.swing.JOptionPane; public class test5cop3530{ public static void main(String[] args) { BaseObArr array; array = new BaseObArr(7); //declare counters to record the number of letters A-G int a = 0; int b = 0; int c = 0; int d = 0; int e = 0; int f = 0; int g = 0; File input = new File(args[0]); //create a file named input, assign it to the file run with the program Scanner read; //Create a scanner try { read = new Scanner(input); //wrap a scanner around my input file, call it read String data = read.next(); //create a string from my file //Traverse the String and count how many times I see and A-G int i = 0; while(i < data.length()); { if(data.charAt(i)=='A') { a++; i++; } else if(data.charAt(i)=='B') { b++; i++; } else if(data.charAt(i)=='C') { c++; i++; } else if(data.charAt(i)=='D') { d++; i++; } else if(data.charAt(i)=='E') { e++; i++; } else if(data.charAt(i)=='F') { f++; i++; } else if(data.charAt(i)=='G') { g++; i++; } else i++; } } catch(Exception ex) { ex.printStackTrace(); } //Check to make sure the values are correct System.out.print("a is " +a+ "\nb is "+b+"\nc is "+c+"\nd is "+d+"\ne is "+e+"\nf is "+f+"\ng is "+g); ...