Hi All,
I need help with try catch statement at the statement. for code
myChar = s.readLine().charAt(0);
I keep getting error: can't find variable myCar and s if te remove the whole try catch statment I get error: unreported exeception java.io.IOException; must be caught or declared to be thrown on the line where this code ismyChar = s.readLine().charAt(0);
Please point me in the right direction
import java.io.*;
import java.util.*;
public class Shorthand
{
//TODO Complete the isVowel method
public boolean isVowel(char c)
{
char myChar;
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
myChar = s.readLine().charAt(0);
if (myChar == 'a' || myChar == 'e' || myChar == 'i' || myChar == 'o' || myChar == 'u')
if (myChar == 'A'|| myChar == 'E'|| myChar == 'I'|| myChar == 'O'|| myChar == 'U')
{
return true;
}
else
{
return false;
}
}
//TODO Complete the shorthand method
public String shorthand(String in)
{
StringBuilder vowel = new StringBuilder();
StringBuilder result = new StringBuilder(in);
result = null;
for(int i = 0;i < in.length(); i++)
{
char myChar = in.charAt(i);
if (isVowel(myChar))
{
vowel.append(myChar);
}
result.append(vowel);
return result.toString().trim();
}
}
//TODO Complete the run method
public void run() throws IOException
{
String yourLine;
Scanner sc = new Scanner(System.in);
yourLine = sc.nextLine();
while(!yourLine.equals("*"));
{
System.out.println("Enter your line of text");
}
yourLine = sc.nextLine();
try
{
System.out.println("Entered try statement");
myChar = s.readLine().charAt(0);
}
catch (Exception ex)
{
System.out.println("Caught excecption " + ex.getMessage());
}
}
}