I am trying to get the program to print how many of each letter of the alphabet is in the bible but it is throwing and error. I am just using a small part of the bible until I get it to run properly. Please help.

import java.io.File; 
import java.io.FileNotFoundException; 
import java.util.Scanner;
import java.util.Arrays;


public class Bible3
{
    public static void main ( String [] args )throws FileNotFoundException
    {
        Scanner dataFile=new Scanner(new File("bible2.txt"));
        int [] countArray = new int[26];
        int alpha = 64;
        while(dataFile.hasNextLine())
            {
                String verse = dataFile.nextLine();
                verse = verse.toLowerCase();

                int colonPosition = verse.indexOf(':');
                int verseLength = verse.length ();
                for (int current = (colonPosition + 1);(current <= (verseLength - 1)); ++ current)
                {
                   if( ((int) verse.charAt(current) >= 97) && ((int)verse.charAt(current) <= 122))
                    {
                        ++ countArray[((int) verse.charAt(current))-97];
                   }
                System.out.println( char(++ alpha) + "  " + countArray[current]);
                }


            }




    }

Here is the text file Bible2

 Genesis|1:1  In the beginning God created the heaven and the earth.
   Genesis|1:2  And the earth was without form, and void; and darkness [was]
 upon the face of the deep. And the Spirit of God moved upon the face of the
 waters.
   Genesis|1:3  And God said, Let there be light: and there was light.
   Genesis|1:4  And God saw the light, that [it was] good: and God divided
 the light from the darkness.
   Genesis|1:5  And God called the light Day, and the darkness he called
 Night. And the evening and the morning were the first day.
   Genesis|1:6  And God said, Let there be a firmament in the midst of the
 waters, and let it divide the waters from the waters.

Here are the errors it is showing

Bible3.java:27: '.class' expected
                System.out.println( char(++ alpha) + "  " + countArray[current]);
                                        ^
Bible3.java:27: ';' expected
                System.out.println( char(++ alpha) + "  " + countArray[current]);
                                           ^
Bible3.java:27: not a statement
                System.out.println( char(++ alpha) + "  " + countArray[current]);
                                            ^
Bible3.java:27: ';' expected
                System.out.println( char(++ alpha) + "  " + countArray[current]);
                                                 ^
Bible3.java:27: not a statement
                System.out.println( char(++ alpha) + "  " + countArray[current]);
                                                                      ^
Bible3.java:27: ';' expected
                System.out.println( char(++ alpha) + "  " + countArray[current]);
                                                                               ^
6 errors

Recommended Answers

All 5 Replies

Sorry did not put it in code brackets

For a start I can see 5 { but only 4 }
and what is char(++ alpha) intended to be?

Are you converting this from C++ or C by chance? The syntax of your code looks very close to C++ or C. You cannot use the syntax in Java. Also, there are certain differences between them...

It looks like you are trying to print out an upper case character in front of each content array? You could simply declare "alpha" as char, and assign 65 to it. Then in the loop, you display it and increment it by 1.

char alpha = 'A';  // int value is 65
while (alpha<91) {
  System.out.print(alpha);
  alpha++;
}

It is supposed to run through the alphabet and tell how many of each is in the bible. Example
A=206548
B=96524
C=657956
and so on

No it is written with JGrasp in Java

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.