Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MyProgram.java:34: error: illegal start of expression
public static boolean isVowel(char letter)
^
MyProgram.java:34: error: illegal start of expression
public static boolean isVowel(char letter)
^
MyProgram.java:34: error: ';' expected
public static boolean isVowel(char letter)
^
MyProgram.java:34: error: '.class' expected
public static boolean isVowel(char letter)
^
MyProgram.java:34: error: ';' expected
public static boolean isVowel(char letter)

What I have tried:

public static boolean isVowel(char letter)
{
boolean vowel = false;
if(letter == ('a'))
{
return true;
}
return false;
if(letter == ('e'))
{
return true;
}
return false;
if(letter == ('i'))
{
return true;
}
return false;
if(letter == ('o'))
{
return true;
}
return false;
if(letter == ('u'))
{
return true;
}
return false;
return vowel;
}//endproblem3


//problem4
public static String longestWord(String s)
{
int count = 0;
String[] c = s.split(" ");
int longest = c[0].length();
String returnStr = "";
for(int i = 1; i < word.length; i++)
{
if(word[i].length()>=four.length()){
{
longest = c[i].length();
count = i; }
}
}
returnStr = c[count];
return returnStr;
//endproblem4
}
Posted
Updated 11-May-21 6:22am
Comments
Richard MacCutchan 11-May-21 12:13pm    
You need to show the code before line 34. There is obviously something wrong before that line. Have you checked to see if there is a missing close brace or semi-colon before line 34?
Krisha Nashte 11-May-21 12:15pm    
import java.util.*;
public class MyProgram
{
public static void main(String[]args)
{
System.out.println("Problem 1 = " + isLetterA('a'));
question(System.out.println("Return true if the supplied character is 'a'"));
System.out.println(daysInMonth(2,1970));
}//end main

//problem1
public static boolean isLetterA(char letter)
{
return letter == 'a';
}//endproblem1

//problem2
public static boolean hasTwoA(String s)
{
boolean q = false;
for (int i = 0; i < s.length() && aCounter <= 2; ++i) {
int count = 0;
for(int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == 'a')
count++;
}
if(count >= 2)
return true;
return q;
}//endproblem2

//problem3
public static boolean isVowel(char letter)
{
boolean vowel = false;
if(letter == ('a'))
{
return true;
}
return false;
if(letter == ('e'))
{
return true;
}
return false;
if(letter == ('i'))
{
return true;
}
return false;
if(letter == ('o'))
{
return true;
}
return false;
if(letter == ('u'))
{
return true;
}
return false;
return vowel;
}//endproblem3


Here is all the code before it

1 solution

You're missing a close curly bracket to end the outer for loop of hasTwoA:
Java
public static boolean hasTwoA(String s)
{
boolean q = false;
for (int i = 0; i < s.length() && aCounter <= 2; ++i) {
                                                      ^
                                                      missing matching bracket.


Do yourself a big favour and stick to one indentation system: when you copy'n'paste code from the internet and mix them up, it becomes really difficult to read and spot problems like this. Picking an indentation style and using it throughout makes problems like thsi so much more obvious ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900