/*This code counts the vowels in strings?
It has to use user defined methods:
*/

import java.lang.String;
import java.io.*;
import java.util.*;

public class vowelConsonant2
{
static Scanner scan = new Scanner(System.in);
public static void main(String args[])
    {

String text;
int actualI, actualC;


System.out.println("Enter the String:");
text = scan.nextLine();
System.out.println("There are " + vowelcounter(actualI,actualC) + " vowels");


    }
public static int vowelcounter(int countv , int i , char c )
    {   countv = 0;

        for (int i = 0; i < text.length(); i++)
        {
        text = text.toLowerCase();
        char c = text.charAt(i);
            if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
            {countv++;
            return countv;}
    }

}

Recommended Answers

All 6 Replies

You may have "enough braces", but you don't have an equal number of { (five) and } (four).
Proper indntation would make the error immediately obvious.

commented: /* It's still giving me the same error. vowelConsonant2.java:30: error: reached end of file while parsing } ^ 1 error */ import java.lang.String; import java.io.*; import java.util.*; public class vowelConsonant2{ static Scanner scan = new Scanner(Syste +0
/* It's still giving me the same error.
vowelConsonant2.java:30: error: reached end of file while parsing
}
^
1 error */

import java.lang.String;
import java.io.*;
import java.util.*;

public class vowelConsonant2{
static Scanner scan = new Scanner(System.in);
public static void main(String args[]){

String text;
int actualCountV, actualI; // Actual parameters of vowelcounter()
char  actualC ; // Actual parameter of vowelcounter()

System.out.println("Enter the String:");
text = scan.nextLine(); //Entered string will be assigned to variable text.
System.out.println("There are " + vowelcounter(actualCountV, actualI,actualC) + " vowels");// There are (number of vowels) vowels

}


public static int vowelcounter(int countv , int i , char c ){ // formal parameter of vowelcounter
countv = 0;
for (int i = 0; i < text.length(); i++) //This will check the indexes of the String one by one. It will stop when it exceeds the length of the string.
{
text = text.toLowerCase(); // The conditions are in lowercase so we have to convert the entire string to lowercase.
char c = text.charAt(i); //assign char c with value of i. i will keep increasing.
if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') // if a e i o u...
{countv++;} // +1 to the value of countv //return countv

}
return countv;
}

you still don't have an equal number of { (five) and } (four).
Proper indentation will make the error immediately obvious.

Go through the code and find the matching } for every {.
Some editors will do this when you position the cursor on a { and press a key combo: Ctrl+] on mine) the editor wll move the cursor to the pairing }

Otherwise print the listing on paper and use a pencil to connect each { to its pairing }
import java.lang.String;
import java.io.*;
import java.util.*;

public class vowelConsonant2
{
static Scanner scan = new Scanner(System.in);
static  String text = "";

static int actualCountV, actualI;
static char actualC ; // Actual parameters of vowelcounter()

static int actualCountC, actualJ;
static char actualD ; // Actual parameters of consonantcounter()

static int actualCountS, actualK;
static char actualE ; // Actual parameters of spacecounter()


static int actualCountN, actualL;
static char actualF ; // Actual parameters of numbercountercounter()

public static void main(String args[])
{





System.out.println("Enter the String:");
text = scan.nextLine(); //Entered string will be assigned to variable text.
System.out.println("There are " + vowelcounter(actualCountV, actualI, actualC) + " vowels.");// There are (number of vowels) vowels
System.out.println("There are " + consonantcounter(actualCountC, actualJ, actualD) + " consonants.");
System.out.println("There are " + spacecounter(actualCountS, actualK, actualE) + " spaces.");
System.out.println("There are " + numbercounter(actualCountN, actualL, actualF) + " numbers.");
}

/*COUNTS VOWELS*/
public static int vowelcounter(int countv , int i , char c )// formal parameter of vowelcounter
{
countv = 0;
for ( i = 0; i < text.length(); i++) //This will check the indexes of the String one by one. It will stop when it exceeds the length of the string.
{
text = text.toLowerCase(); // The conditions are in lowercase so we have to convert the entire string to lowercase.
c = text.charAt(i); //assign char c with value of i. i will keep increasing.
if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') // if a e i o u...
{countv++;} // +1 to the value of countv //return countv
}
return countv;
}

/*COUNTS CONSONANTS*/
public static int consonantcounter(int countc , int j , char d )
{
countc = 0;
for ( j = 0; j < text.length(); j++)
{
text = text.toLowerCase();
d = text.charAt(j);
if (d=='b' || d=='c' || d=='d' || d=='f' || d=='g' || d=='h' || d=='j' || d=='k' || d=='l' || d=='m' || d=='n' || d=='p' || d=='q' || d=='r' || d=='s' || d=='t' || d=='v' || d=='w' || d=='x' || d=='y' || d=='z')
{countc++;}
}
return countc;
}

/*COUNTS SPACES*/
public static int spacecounter(int counts , int k , char e )
{
counts = 0;
for ( k = 0; k < text.length(); k++)
{
text = text.toLowerCase();
e = text.charAt(k);
if (e==' ' )
{counts++;}
}
return counts;
}

/*COUNTS NUMBERS*/
public static int numbercounter(int countn , int l , char f )
{
countn = 0;
for ( l = 0; l < text.length(); l++)
{
text = text.toLowerCase();
f = text.charAt(l);
if (f=='0' || f=='1' || f=='2' || f=='3' || f=='4' || f=='5' || f=='6' || f=='7' || f=='8' || f=='9' )
{countn++;}
}
return countn;
}

}

You still have not properly indented the code. It makes it very hard to read.

commented: It's indented but it gets messed up when I paste it here.. :p +0
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.